Table of Contents

June 9, 2026 · View on GitHub

Quality Gate StatusBugsCoverageLines of CodeReliability RatingMaintainability RatingSecurity Rating Build Status License NuGetDownloads Ask DeepWiki


Table of Contents


Description

Rxmxnx.PInvoke.Extensions is a comprehensive library designed to streamline and enhance the interaction between .NET and native P/Invoke methods.

Features

  • UTF-8/ASCII String Handling: Seamlessly work with UTF-8 encoded strings in interop contexts. More info
  • Managed Buffers: Dynamically allocate object references on the stack with minimal effort. More info
  • Safe Memory Manipulation: Eliminate direct pointer manipulation and unsafe code requirements. More info

Use Case Roadmap

Use this library when the problem benefits from explicit memory intent, scoped lifetimes, or low-allocation data access:

ScenarioLibrary areaTypical use
UTF-8 text in interop or managed protocolsCString, CStringSequence, CStringBuilderWork with UTF-8 data for native APIs, ASP.NET, System.Text.Json, gRPC-style payloads, or other pipelines where avoiding repeated encoding work matters.
Typed native pointers without spreading unsafeValPtr<T>, ReadOnlyValPtr<T>, FuncPtr<TDelegate>Keep pointer intent visible in signatures while still interoperating with IntPtr, delegates, and native exports.
Scoped fixed memory accessIFixedContext<T>, IReadOnlyFixedContext<T>, WithSafeFixed, WithSafeReadOnlyFixedKeep pointer validity tied to a callback or using scope while still exposing spans, references, and typed fixed contexts.
Native heap allocation with .NET lifetime semanticsNativeUtilities.HeapAlloc<T>()Allocate unmanaged buffers and release them through IDisposable instead of manually pairing framework-specific alloc/free calls.
Binary reinterpretation and memory viewsAsBytes, AsValues, ToBytes, ToValue, multidimensional array AsSpan/AsMemoryInspect, serialize, hash, transform, or reinterpret memory without unnecessary copies when the layout is already known.
Stack-backed references and scoped temporary buffersBufferManager, ScopedBuffer<T>Prefer stack-first, scope-bound temporary storage for parsers, serializers, formatting, or high-throughput pipelines where reducing heap pressure matters.
Runtime/AOT/platform checksAotInfo, SystemInfo, IsImageMethod, IsImageCode, IsLiteral, MayBeNonLiteralAdapt behavior for Native AOT, Mono partial AOT, literal/read-only memory, platform-specific exports, or constrained runtimes.

A simple decision rule:

  • Use it if the code is performance-sensitive, interoperates with native APIs, needs explicit memory lifetime, handles UTF-8 text, reinterprets binary data, benefits from typed pointer contracts, needs stack-backed references and scoped temporary storage, or must adapt to runtime/AOT/platform differences.
  • Skip it if all those flows are already covered, direct unsafe code is preferred, pointer intent does not need design-time validation, stack-backed references are not needed, UTF-8-specific handling is not part of the workload, and runtime/AOT/platform checks are irrelevant.

Getting Started

Installation

Install the library via NuGet:

dotnet add package Rxmxnx.PInvoke.Extensions

Note: This package officially supports .NET 8.0 and later. However, this package offers limited support for .NET Standard 2.1-compatible runtimes and legacy support for .NET 7.0 and earlier.

Framework Support

This package guarantees both binary and source compatibility across all supported target frameworks, from .NET Standard 2.1 up to .NET 10.0.

Here is a detailed description of the specific characteristics of how this package is compiled for each of the supported target frameworks, along with the type of support provided for each one.

.NET Standard 2.1 — Limited Support
  • Static Virtual Members: No [¹]
  • Generic ref struct: No
  • MemoryMarshal (shim implemented):
    • CreateReadOnlySpanFromNullTerminated [²]
    • GetArrayDataReference [³]
  • Rune (shim implemented):
    • EncodeToUtf8, DecodeFromUtf8, DecodeFromUtf16 [²]
  • Enum (shim implemented):
    • Enum.GetName<T> [⁴]
  • Convert (shim implemented):
    • ToHexString [²]
  • Dependencies:
    • System.Runtime.CompilerServices.Unsafe 5.0
    • System.Collections.Immutable 5.0
.NET Core 3.0 — Legacy (Limited)
  • Inherits from .NET Standard 2.1
  • Adds support for:
    • System.Text.Json
    • NativeLibrary
  • Rune (native implemented): Yes
  • Dependencies:
    • Same as .NET Standard 2.1
    • System.Text.Json 5.0.2
.NET Core 3.1 — Legacy
  • Inherits from .NET Core 3.0
  • Updated Dependencies:
    • System.Runtime.CompilerServices.Unsafe 6.0
    • System.Collections.Immutable 6.0
    • System.Text.Json 6.0.11
.NET 5.0 — Legacy
  • Inherits from .NET Core 3.1
  • Enum (native implemented): Yes
  • Convert (native implemented): Yes
.NET 6.0 — LTS (Extended)
  • Inherits from .NET 5.0
  • Updated Dependencies:
    • System.Runtime.CompilerServices.Unsafe 6.1.2
    • System.Collections.Immutable 8.0
    • System.Text.Json 8.0.5
.NET 7.0 — Extended
  • Inherits from .NET 6.0
  • Static Virtual Members: Yes [¹]
  • Adds support for:
    • Marshalling
.NET 8.0 — LTS
  • Inherits from .NET 7.0
  • No dependencies required
.NET 9.0 — Current
  • Inherits from .NET 8.0
  • Generic ref struct: Yes [⁵]
.NET 10.0 — LTS (Current)
  • Inherits from .NET 9.0
  1. AOT detection should be performed via reflection.
  2. Uses CoreCLR implementations from .NET 6.0. Simpler alternatives may be substituted in .NET Standard 2.1.
  3. Retrieving references to multidimensional array data should be done using static delegates, and managed buffer registration should be handled through buffer binding.
  4. Internally relies on Enum.GetName(Type, Object).
  5. Value-type pointers support ref struct generics, but due to C# compiler restrictions, some methods must be implemented in IL.

The specifications compatible with Rxmxnx.PInvoke.Extensions are:

.NET

This package supports .NET 5.0 and later through assemblies compiled for each target framework. However, backward compatibility with earlier frameworks is maintained when possible, taking into account potential feature limitations.

Rxmxnx.PInvoke.Extensions automatically adapts its behavior to the different platforms supported by these specifications.

Currently, functionality is guaranteed on the following runtimes:

  • CoreCLR: The default runtime for .NET/.NET Core desktop platforms.
  • Mono VM: The default runtime for mobile platforms and Blazor WebAssembly.
Unity

Through the assembly compiled for .NET Standard 2.1, Rxmxnx.PInvoke.Extensions can be used in Unity projects, adapting to the various versions of the internal Mono runtime and supported platforms.

The only requirement is the presence of version 6.0 or later of the System.Runtime.CompilerServices.Unsafe assembly. Using the build compiled for .NET Standard 2.0 is recommended.

Xamarin (Android, iOS, macOS)

Since Rxmxnx.PInvoke.Extensions is compiled for .NET Standard 2.1, it can be used in legacy Xamarin projects by adding it directly as a NuGet package reference. This will also reference version 5.0 of the System.Runtime.CompilerServices.Unsafe package (which contains assembly version 6.0).

However, for new projects it is recommended to use the latest version of the package (6.1.2).

To build Xamarin applications, Visual Studio 2019 or Visual Studio 2019 for Mac is required.

.NET Core 3.x

This package supports .NET Core 3.0 and .NET Core 3.1 through assemblies compiled specifically for those frameworks. Backward compatibility with the .NET Standard 2.1 assembly is also maintained, considering potential feature differences such as native support for System.Text.Json and native libraries.

The .NET Core 3.0 assembly uses a different version of System.Text.Json than .NET Core 3.1, which may result in slightly different behavior.

Blazor WebAssembly 3.2

Through the assembly compiled for .NET Standard 2.1, this package supports the initial version of Blazor WebAssembly, which ran on a WASM build of the Mono runtime.

To use it, you only need to add the NuGet package reference (which will also reference version 5.0 of the System.Runtime.CompilerServices.Unsafe package). Additionally, the publishing process must be intercepted to ensure that the assembly from this package is used instead of the version bundled with the WASM runtime.

Mono Framework

As it is compiled for .NET Standard 2.1, Rxmxnx.PInvoke.Extensions is compatible with the Mono Framework, using the .NET Framework 4.5 facades and the System.Runtime.CompilerServices.Unsafe package version 5.0 across the supported platforms.

AOT Support

This package is AOT-friendly, all of its features support both Mono AOT and Native AOT, including full AOT and the obsolete reflection-free mode.

The only features that require reflection are:

  • Buffer preparation and auto-composition when no binary buffer is registered.
  • AOT detection when targeting .NET 5.0 or earlier.
  • AOT detection on .NET 7.0 and later when running on Web or Mobile platforms only.

Rxmxnx.PInvoke.Extensions supports the following AOT compilation models, regardless of the framework used to build them:

Mono AOT

Rxmxnx.PInvoke.Extensions supports Mono AOT compilation in Full, Hybrid, and LLVM modes, subject only to the level of support provided by the target platform and runtime.

This includes Mono-based runtimes that support .NET Standard 2.1, such as Mono Framework, Xamarin, Blazor WebAssembly 3.x, and Unity, as well as newer Mono-based runtimes compatible with .NET 5.0 or later, used by modern mobile platforms and Blazor WebAssembly on .NET.

ReadyToRun (R2R)

Rxmxnx.PInvoke.Extensions supports ReadyToRun (R2R) hybrid AOT compilation based on CoreCLR, available since * .NET Core 3.0* and still supported in current versions of .NET.

NativeAOT

Rxmxnx.PInvoke.Extensions supports CoreCLR-based NativeAOT, available since .NET 7.0 and supported by current versions of .NET.

One of the key design goals of Rxmxnx.PInvoke.Extensions is to rely on minimal reflection, making it well suited for NativeAOT scenarios. This approach helps avoid common issues such as N+1 reflection patterns, while most functionality is implemented using statically compiled code.

The library can also adapt—though with limited functionality—to the legacy reflection-free mode supported by early NativeAOT implementations.

Unity IL2CPP

As mentioned previously, Unity supports Rxmxnx.PInvoke.Extensions through the assembly compiled for .NET Standard 2.1. Consequently, the library can also be used when IL2CPP compilation is enabled.

However, since certain multidimensional array flattening features are statically included, IL2CPP may generate invalid C++ identifiers for array indices greater than 17 if these members are not removed by the linker.

The following .NET utility can be used to work around this issue. When executed with the directory containing the C++ source files generated by IL2CPP, it adjusts the generated code. Afterward, recompiling the project in Unity without further modifications will reuse the corrected files and allow the compilation to succeed.

if (args.Length != 1) 
{
    Console.WriteLine("Invalid IL2CPP source code folder.");
    return;
}
Dictionary<Char, String> map = new()
{
	{ (Char)(18 + 'i'), "a" },
	{ (Char)(19 + 'i'), "b" },
	{ (Char)(20 + 'i'), "c" },
	{ (Char)(21 + 'i'), "d" },
	{ (Char)(22 + 'i'), "e" },
	{ (Char)(23 + 'i'), "f" },
	{ (Char)(24 + 'i'), "g" },
	{ (Char)(25 + 'i'), "h" },
	{ (Char)(26 + 'i'), "_i" },
	{ (Char)(27 + 'i'), "_j" },
	{ (Char)(28 + 'i'), "_k" },
	{ (Char)(29 + 'i'), "_l" },
	{ (Char)(30 + 'i'), "_m" },
	{ (Char)(31 + 'i'), "_n" },
};
String[] replacements = ["l2cpp_array_size_t {0}", "{0}, {0}Bound", "{0}Bound + {0}",];
foreach (String sourceCodeFile in new DirectoryInfo(args[0]).GetFiles("*.cpp").Select(f => f.FullName))
{
	String sourceCodeContent = await File.ReadAllTextAsync(sourceCodeFile);
	Boolean modified = false;
	foreach (Char invalidBound in map.Keys)
	{
		foreach (String replacement in replacements)
		{
			String o = String.Format(replacement, invalidBound);
			if (!sourceCodeContent.Contains(o, StringComparison.OrdinalIgnoreCase)) continue;
			String r = String.Format(replacement, map[invalidBound]);
			sourceCodeContent = sourceCodeContent.Replace(o, r,  StringComparison.OrdinalIgnoreCase);
			modified = true;
		}
	}
	if (modified) 
    {
		await File.WriteAllTextAsync(sourceCodeFile, sourceCodeContent);
        Console.WriteLine($"{sourceCodeFile} fixed.");
    }
}

Since Rxmxnx.PInvoke.Extensions, across its different builds, uses minimal reflection in favor of statically reachable code, it is compatible with various linking and trimming tools, ranging from the classic Mono Linker to the modern ILLink.

Visual Basic .NET Support

Some APIs in Rxmxnx.PInvoke.Extensions are not directly compatible with Visual Basic .NET due to language limitations. The Rxmxnx.PInvoke.VisualBasic namespace provides equivalent delegate definitions specifically designed for use in Visual Basic .NET.

These delegates provide VB.NET-compatible access to selected non-compliant Rxmxnx.PInvoke.Extensions APIs.


Abstractions

Rxmxnx.PInvoke.Extensions provides abstractions for managed handling of references and fixed memory segments.

Reference Interfaces

These interfaces represent a safe way to access a managed reference of a specific type.

IReadOnlyReferenceable<T>

This interface exposes a read-only reference to an object of type T, allowing the object to be used without modification.

Notes:

  • This interface inherits from IEquatable<IReadOnlyReferenceable<T>>.
  • This type allows public implementation or inheritance.
  • Starting with .NET 9.0, T can be a ref struct.

Properties:

  • Reference

    Gets the read-only reference to the instance of an object of type T.

IReferenceable<T>

This interface exposes a reference to an object of type T, allowing the object to be used and potentially modified.

Notes:

  • This interface inherits from IReadOnlyReferenceable<T> and IEquatable<IReferenceable<T>>.
  • This type allows public implementation or inheritance.
  • Starting with .NET 9.0, T can be a ref struct.

Properties:

  • Reference

    Gets the reference to the instance of an object of type T.

Wrapper Interfaces

These interfaces represent a safe way to access a value or managed object of a specific type.

IWrapper<T>

This interface defines a wrapper for a T object.

Notes:

  • This interface inherits from IEquatable<T>. This type allows public implementation or inheritance.

Properties:

  • Value

    The wrapped T object.

Static Methods:

  • Create(T?)

    Creates a new instance of an object that implements IWrapper<T> interface.

Non-generic interface

IWrapper is a non-generic interface that exposes static methods for creating specific types of IWrapper<T> for concrete cases of value types, nullable values, and non-nullable reference types.

Note: IWrapper contains a public interface IBase<T> that allows covariance. Starting with .NET 9.0, T can be a ref struct.

Static Methods:
  • Create<TValue>(TValue)

    Creates a new instance of an object that implements IWrapper<TValue> interface.

    Note: TValue generic type is struct.

  • CreateNullable<TValue>(TValue?)

    Creates a new instance of an object that implements IWrapper<TValue?> interface.

    Note: TValue generic type is struct.

  • CreateObject<TObject>(TObject)

    Creates a new instance of an object that implements IWrapper<TObject> interface.

    Note: TObject generic type is a reference type.

IMutableWrapper<T>

This interface defines a wrapper for an object whose value can be modified.

Note: This interface inherits from IWrapper<T>. This type allows public implementation or inheritance.

Properties:

  • Value

    The wrapped T object.

Static Methods:

  • Create(T?)

    Creates a new instance of an object that implements IMutableWrapper<T> interface.

Non-generic interface

IMutableWrapper is a non-generic interface that exposes static methods for creating specific types of IMutableWrapper<T> for concrete cases of value types, nullable values, and non-nullable reference types.

Static Methods:
  • Create<TValue>(TValue)

    Creates a new instance of an object that implements IMutableWrapper<TValue> interface.

    Note: TValue generic type is struct.

  • CreateNullable<TValue>(TValue?)

    Creates a new instance of an object that implements IMutableWrapper<TValue?> interface.

    Note: TValue generic type is struct.

  • CreateObject<TObject>(TObject)

    Creates a new instance of an object that implements IMutableWrapper<TObject> interface.

    Note: TObject generic type is a reference type.

IMutableReference<T>

This interface exposes a wrapper for T object that can be referenced and whose value can be modified.

Note: This interface inherits from IMutableWrapper<T> and IReferenceable<T>. This type allows public implementation or inheritance.

Properties:

  • Reference

    Reference to T wrapped instance.

Static Methods:

  • Create(T?)

    Creates a new instance of an object that implements IMutableReference<T> interface.

Non-generic interface

IMutableReference is a non-generic interface that exposes static methods for creating specific types of IMutableReference<T> for concrete cases of value types, nullable values, and non-nullable reference types.

Static Methods:
  • Create<TValue>(TValue)

    Creates a new instance of an object that implements IMutableReference<TValue> interface.

    Note: TValue generic type is struct.

  • CreateNullable<TValue>(TValue?)

    Creates a new instance of an object that implements IMutableReference<TValue?> interface.

    Note: TValue generic type is struct.

  • CreateObject<TObject>(TObject)

    Creates a new instance of an object that implements IMutableReference<TObject> interface.

    Note: TObject generic type is a reference type.

Fixed memory Interfaces

These interfaces represent a safe way to access a fixed address of native or managed memory.

IFixedPointer

Interface representing a pointer to a fixed block of memory.

Note: This type allows public implementation or inheritance.

Properties:

  • Pointer Gets the pointer to the fixed block of memory.

Disposable interface

IFixedPointer.IDisposable representing a disposable IFixedPointer object. This interface is used for managing fixed memory blocks that require explicit resource cleanup.

Note: This interface inherits from IFixedPointer and System.IDisposable. This type allows public implementation or inheritance.

IFixedMethod<TMethod>

Interface representing a method whose memory address is fixed in memory.

Note: This interface inherits from IFixedPointer. This type allows public implementation or inheritance.

Properties:

  • Method Gets the delegate that points to the fixed method in memory.
  • FunctionPointer Gets the function pointer to the fixed method in memory.
IReadOnlyFixedMemory

Interface representing a read-only fixed block of memory.

Note: This interface inherits from IFixedPointer. This type allows public implementation or inheritance.

Properties:

  • Bytes Gets a read-only binary span over the fixed block of memory.
  • Objects Gets a read-only object span over the fixed block of memory.

Methods:

  • AsBinaryContext()

    Creates a new instance of IReadOnlyFixedContext<Byte> from the current instance.

  • AsObjectContext()

    Creates a new instance of IReadOnlyFixedContext<Object> from the current instance.

Disposable interface

IReadOnlyFixedMemory.IDisposable representing a disposable IReadOnlyFixedMemory object. This interface is used for managing fixed memory blocks that require explicit resource cleanup.

Note: This interface inherits from IReadOnlyFixedMemory and IFixedPointer.IDisposable. This type allows public implementation or inheritance.

IReadOnlyFixedMemory<T>

Interface representing a read-only fixed block of memory for a specific type.

Note: This interface inherits from IReadOnlyFixedMemory. This type allows public implementation or inheritance.

Properties:

  • ValuePointer Gets the value pointer to the read-only fixed block of memory.
  • Values

    Gets a read-only T span over the fixed block of memory.

Disposable interface

IReadOnlyFixedMemory<T>.IDisposable representing a disposable IReadOnlyFixedMemory<T> object. This interface is used for managing fixed memory blocks that require explicit resource cleanup.

Note: This interface inherits from IReadOnlyFixedMemory<T> and IReadOnlyFixedMemory.IDisposable. This type allows public implementation or inheritance.

IFixedMemory

Interface representing a fixed block of memory.

Note: This interface inherits from IReadOnlyFixedMemory. This type allows public implementation or inheritance.

Properties:

  • Bytes Gets a binary span over the fixed block of memory.
  • Objects Gets an object span over the fixed block of memory.

Methods:

  • AsBinaryContext()

    Creates a new instance of IFixedContext<Byte> from the current instance.

  • AsObjectContext()

    Creates a new instance of IFixedContext<Object> from the current instance.

Disposable interface

IFixedMemory.IDisposable representing a disposable IFixedMemory object. This interface is used for managing fixed memory blocks that require explicit resource cleanup.

Note: This interface inherits from IFixedMemory and IReadOnlyFixedMemory.IDisposable. This type allows public implementation or inheritance.

IFixedMemory<T>

Interface representing a fixed block of memory for a specific type.

Note: This interface inherits from IReadOnlyFixedMemory<T> and IFixedMemory<T>. This type allows public implementation or inheritance.

Properties:

  • ValuePointer Gets the value pointer to the fixed block of memory.
  • Values

    Gets a T span over the fixed block of memory.

Disposable interface

IFixedMemory<T>.IDisposable representing a disposable IFixedMemory<T> object. This interface is used for managing fixed memory blocks that require explicit resource cleanup.

Note: This interface inherits from IReadOnlyFixedMemory<T> and IFixedMemory.IDisposable. This type allows public implementation or inheritance.

IReadOnlyFixedReference<T>

This interface exposes a read-only reference to an object of type T, allowing the object to be used without modification.

Note: This interface inherits from IReadOnlyReferenceable<T> and IReadOnlyFixedMemory. This type allows public implementation or inheritance. Starting with .NET 9.0, T can be a ref struct.

Methods:

  • Transformation(out IReadOnlyFixedMemory)

    Reinterprets the read-only T fixed memory reference as a read-only TDestination memory reference.

Disposable interface

IReadOnlyFixedReference<T>.IDisposable representing a disposable IReadOnlyFixedReference<T> object. This interface is used for managing fixed memory blocks that require explicit resource cleanup.

Note: This interface inherits from IReadOnlyFixedReference<T> and IReadOnlyFixedMemory.IDisposable. This type allows public implementation or inheritance.

IFixedReference<T>

This interface represents a mutable reference to a fixed memory location.

Note: This interface inherits from IReferenceable<T>, IReadOnlyFixedReference<T> and IFixedMemory. This type allows public implementation or inheritance. Starting with .NET 9.0, T can be a ref struct.

Methods:

  • Transformation(out IFixedMemory)

    Reinterprets the T fixed memory reference as a TDestination memory reference.

  • Transformation(out IReadOnlyFixedMemory)

    Reinterprets the T fixed memory reference as a TDestination memory reference.

Disposable interface

IFixedReference<T>.IDisposable representing a disposable IFixedReference<T> object. This interface is used for managing fixed memory blocks that require explicit resource cleanup.

Note: This interface inherits from IFixedReference<T> and IReadOnlyFixedReference<T>.IDisposable. This type allows public implementation or inheritance.

IReadOnlyFixedContext<T>

Interface representing a context from a read-only block of fixed memory.

Note: This interface inherits from IReadOnlyFixedMemory<T>. This type allows public implementation or inheritance.

Methods:

  • Transformation(out IReadOnlyFixedMemory)

    Reinterprets the T fixed memory block as TDestination memory block.

Disposable interface

IReadOnlyFixedContext<T>.IDisposable representing a disposable IReadOnlyFixedContext<T> object. This interface is used for managing fixed memory blocks that require explicit resource cleanup.

Note: This interface inherits from IReadOnlyFixedContext<T> and IReadOnlyFixedMemory<T>.IDisposable. This type allows public implementation or inheritance.

IFixedContext<T>

Interface representing a context from a block of fixed memory.

Note: This interface inherits from IReadOnlyFixedContext<T> and IFixedMemory<T>. This type allows public implementation or inheritance.

Methods:

  • Transformation(out IFixedMemory)

    Reinterprets the T fixed memory block as a TDestination memory block.

  • Transformation(out IReadOnlyFixedMemory) Reinterprets the `T` fixed memory block as a `TDestination` memory block.

Disposable interface

IFixedContext<T>.IDisposable representing a disposable IFixedContext<T> object. This interface is used for managing fixed memory blocks that require explicit resource cleanup.

Note: This interface inherits from IFixedContext<T> and IFixedMemory<T>.IDisposable. This type allows public implementation or inheritance.

Functional Interfaces

These interfaces expose functionalities for internal types or default functional implementations.

IEnumerableSequence<T>

Defines methods to support a simple iteration over a sequence of a specified type.

Notes:

  • This interface inherits from IEnumerable<T>. This type allows public implementation or inheritance.
  • Starting with .NET 9.0, T can be a ref struct.

Methods:

  • GetItem(Int32) Retrieves the element at the specified index.
  • GetSize() Retrieves the total number of elements in the sequence.

Protected Methods:

  • DisposeEnumeration(Int32)

    Method to call when IEnumerator<T> is disposing.

    Note: This method is not available in .NET Standard 2.1 library.

Protected Static Methods:

  • CreateEnumerator(IEnumerableSequence<T>, Action<IEnumerableSequence<T>gt;?)

    This static method allows the creation of an internal IEnumerator<T> instance using an IEnumerableSequence<T>. The Action delegate is used during the enumerator's disposal.

    Starting with .NET Core 3.0, the implementation of the DisposeEnumeration(Int32) method is ignored. However, this method may still be required when targeting a .NET Standard 2.1 library on the Mono framework.

IUtf8FunctionState<TSelf>

Interface representing a value state for functional CString creation.

Notes:

  • TSelf generic type is struct. This type allows public implementation or inheritance.
  • This type is available only on .NET 7.0 and later.

Static Abstract/Virtual Properties:

  • Alloc Function that allocates a state instance.

Properties:

  • IsNullTerminated Indicates whether resulting UTF-8 text is null-terminated.

Static Abstract/Virtual Methods:

  • GetSpan(TSelf) Retrieves the span from state.
  • GetLength(in TSelf) Retrieves the span length from state.
IManagedBuffer<T>

This interfaces exposes a managed buffer.

Note: This type does not allow public implementation or inheritance.

Static Methods:

  • GetMetadata<TBuffer>()

    Retrieves the BufferTypeMetadata<T> instance from TBuffer.

IManagedBinaryBuffer<T>

This interfaces exposes a binary managed buffer.

Note: This interface inherits from IManagedBuffer<T>. This type does not allow public implementation or inheritance.

Properties:

  • Metadata<TBuffer>()

    Retrieves the BufferTypeMetadata<T> instance from current instance.

IManagedBinaryBuffer<TBuffer, T>

This interfaces exposes a binary managed buffer.

Note: TBuffer generic type is struct. This interface inherits from IManagedBinaryBuffer<T>. This type not allows public implementation or inheritance.

Span Delegates

These delegates encapsulate methods that operate with Span instances.

ReadOnlySpan<T> ReadOnlySpanFunc<T>()

Encapsulates a method that has no parameters and returns a read-only span of type T.

ReadOnlySpan<T> ReadOnlySpanFunc<T, in TState>(TState)

Encapsulates a method that has a TState parameter and returns a read-only span of type T.

Note: Starting with .NET 9.0, TState can be a ref struct.

TResult SpanFunc<T, in TArg, out TResult>(Span<T>, TArg)

Encapsulates a method that receives a span of type T, a state object of type TArg and returns a result of type TResult.

Note: Starting with .NET 9.0, TState can be a ref struct.

TResult ReadOnlySpanFunc<T, in TArg, out TResult>(Span<T>, TArg)

Encapsulates a method that receives a read-only span of type T, a state object of type TArg and returns a result of type TResult.

Note: Starting with .NET 9.0, TState can be a ref struct.

Fixed memory Delegates

These delegates encapsulate methods that operate with fixed memory blocks.

void FixedAction(in IFixedMemory)

Represents an action that operates on a fixed memory instance.

void FixedAction<in TArg>(in IFixedMemory, TArg)

Represents an action that operates on a fixed memory instance using an additional state object.

Note: Starting with .NET 9.0, TState can be a ref struct.

void ReadOnlyFixedAction(in IReadOnlyFixedMemory)

Represents an action that operates on a read-only fixed memory instance.

void ReadOnlyFixedAction<in TArg>(in IReadOnlyFixedMemory, TArg)

Represents an action that operates on a read-only fixed memory instance using an additional state object.

Note: Starting with .NET 9.0, TState can be a ref struct.

TResult FixedFunc<out TResult>(in IFixedMemory)

Represents a function that operates on a fixed memory instance.

TResult FixedFunc<in TArg, out TResult>(in IFixedMemory, TArg)

Represents a function that operates on a fixed memory instance using an additional state object.

Note: Starting with .NET 9.0, TState can be a ref struct.

TResult ReadOnlyFixedFunc<out TResult>(in IReadOnlyFixedMemory<T>)

Represents a function that operates on a read-only fixed memory instance.

TResult ReadOnlyFixedFunc<in TArg, out TResult>(in IReadOnlyFixedMemory<T>, TArg)

Represents a function that operates on a read-only fixed memory instance using an additional state object.

Note: Starting with .NET 9.0, TState can be a ref struct.

Fixed memory context Delegates

These delegates encapsulate methods that operate on fixed memory blocks of a specific type.

void FixedContextAction<T>(in IFixedContext<T>)

Encapsulates a method that receives an instance of IFixedContext<T>.

void FixedContextAction<T, in TArg,>(in IFixedContext<T>, TArg)

Encapsulates a method that receives an instance of IFixedContext<T> and a state object of type TArg.

Note: Starting with .NET 9.0, TState can be a ref struct.

void ReadOnlyFixedContextAction<T>(in IReadOnlyFixedContext<T>)

Encapsulates a method that receives an instance of IReadOnlyFixedContext<T>.

void ReadOnlyFixedContextAction<T, in TArg,>(in IFixedContext<T>, TArg)

Encapsulates a method that receives an instance of IReadOnlyFixedContext<T> and a state object of type TArg.

Note: Starting with .NET 9.0, TState can be a ref struct.

TResult FixedContextFunc<T, out TResult>(in IFixedContext<T>)

Encapsulates a method that receives an instance of IFixedContext<T> and returns a value of type TResult.

TResult FixedContextFunc<T, in TArg, out TResult>(in IFixedContext<T>, TArg)

Encapsulates a method that receives an instance of IFixedContext<T> and returns a value of type TResult.

Note: Starting with .NET 9.0, TState can be a ref struct.

TResult ReadOnlyFixedContextFunc<T, out TResult>(in IReadOnlyFixedContext<T>)

Encapsulates a method that receives an instance of IReadOnlyFixedContext<T> and returns a value of type TResult.

TResult FixedContextFunc<T, in TArg, out TResult>(in IReadOnlyFixedContext<T>, TArg)

Encapsulates a method that receives an instance of IReadOnlyFixedContext<T> and returns a value of type TResult.

Note: Starting with .NET 9.0, TState can be a ref struct.

Fixed memory reference Delegates

These delegates encapsulate methods that operate on fixed memory references of a specific type.

void FixedReferenceAction<T>(in IFixedReference<T>)

Encapsulates a method that receives an instance of IFixedReference<T>.

Note: Starting with .NET 9.0, both T and TArg can be ref struct types.

void FixedReferenceAction<T, in TArg,>(in IFixedReference<T>, TArg)

Encapsulates a method that receives an instance of IFixedReference<T> and a state object of type TArg.

Note: Starting with .NET 9.0, both T and TArg can be ref struct types.

void ReadOnlyFixedReferenceAction<T>(in IReadOnlyFixedReference<T>)

Encapsulates a method that receives an instance of IReadOnlyFixedReference<T>.

Note: Starting with .NET 9.0, T can be a ref struct.

void ReadOnlyFixedReferenceAction<T, in TArg,>(in IFixedReference<T>, TArg)

Encapsulates a method that receives an instance of IReadOnlyFixedReference<T> and a state object of type TArg.

Note: Starting with .NET 9.0, both T and TArg can be ref struct types.

TResult FixedReferenceFunc<T, out TResult>(in IFixedReference<T>)

Encapsulates a method that receives an instance of IFixedReference<T> and returns a value of type TResult.

Note: Starting with .NET 9.0, T can be a ref struct.

TResult FixedReferenceFunc<T, in TArg, out TResult>(in IFixedReference<T>, TArg)

Encapsulates a method that receives an instance of IFixedReference<T> and returns a value of type TResult.

Note: Starting with .NET 9.0, both T and TArg can be ref struct types.

TResult ReadOnlyFixedReferenceFunc<T, out TResult>(in IReadOnlyFixedReference<T>)

Encapsulates a method that receives an instance of IReadOnlyFixedReference<T> and returns a value of type TResult.

Note: Starting with .NET 9.0, T can be a ref struct.

TResult FixedReferenceFunc<T, in TArg, out TResult>(in IReadOnlyFixedReference<T>, TArg)

Encapsulates a method that receives an instance of IReadOnlyFixedReference<T> and returns a value of type TResult.

Note: Starting with .NET 9.0, both T and TArg can be ref struct types.

Fixed address method Delegates

These delegates encapsulate methods that operate on methods with a fixed memory address.

void FixedMethodAction<T>(in IFixedMethod<T>)

Encapsulates a method that receives an instance of IFixedMethod<T>.

void FixedMethodAction<T, in TArg,>(in IFixedMethod<T>, TArg)

Encapsulates a method that receives an instance of IFixedMethod<T> and a state object of type TArg.

Note: Starting with .NET 9.0, TState can be a ref struct.

TResult FixedMethodFunc<T, out TResult>(in IFixedMethod<T>)

Encapsulates a method that receives an instance of IFixedMethod<T> and returns a value of type TResult.

TResult FixedMethodFunc<T, in TArg, out TResult>(in IFixedMethod<T>, TArg)

Encapsulates a method that receives an instance of IFixedMethod<T> and returns a value of type TResult.

Note: Starting with .NET 9.0, TState can be a ref struct.

Fixed memory list Delegates

These delegates encapsulate methods that operate on a list of fixed memory blocks.

void FixedListAction(FixedMemoryList)

Encapsulates a method that receives an instance of FixedMemoryList.

void FixedListAction<in TArg,>(FixedMemoryList, TArg)

Encapsulates a method that receives an instance of FixedMemoryList and a state object of type TArg.

Note: Starting with .NET 9.0, TState can be a ref struct.

void ReadOnlyFixedListAction(ReadOnlyFixedMemoryList)

Encapsulates a method that receives an instance of ReadOnlyFixedMemoryList.

void ReadOnlyFixedListAction<in TArg,>(FixedMemoryList, TArg)

Encapsulates a method that receives an instance of ReadOnlyFixedMemoryList and a state object of type TArg.

Note: Starting with .NET 9.0, TState can be a ref struct.

TResult FixedListFunc<out TResult>(FixedMemoryList)

Encapsulates a method that receives an instance of FixedMemoryList and returns a value of type TResult.

TResult FixedListFunc<in TArg, out TResult>(FixedMemoryList, TArg)

Encapsulates a method that receives an instance of FixedMemoryList and returns a value of type TResult.

Note: Starting with .NET 9.0, TState can be a ref struct.

TResult ReadOnlyFixedListFunc<out TResult>(ReadOnlyFixedMemoryList)

Encapsulates a method that receives an instance of ReadOnlyFixedMemoryList and returns a value of type TResult.

TResult FixedListFunc<in TArg, out TResult>(ReadOnlyFixedMemoryList, TArg)

Encapsulates a method that receives an instance of ReadOnlyFixedMemoryList and returns a value of type TResult.

Note: Starting with .NET 9.0, TState can be a ref struct.

UTF-8/ASCII Delegates

These delegates encapsulate methods that allow creating and operating with UTF-8/ASCII text.

void CStringSequenceCreationAction<in TArg>(Span<Byte>, Int32, TArg)

Encapsulates a method that receives a span of bytes, an index and a state object of type TArg.

Note: Starting with .NET 9.0, TState can be a ref struct.

void CStringSequenceAction(FixedCStringSequence)

Encapsulates a method that operates on a FixedCStringSequence instance.

Note: Starting with .NET 9.0, TState can be a ref struct.

void CStringSequenceAction<in TArg>(FixedCStringSequence, TArg)

Encapsulates a method that operates on a FixedCStringSequence instance and a state object of type TArg.

Note: Starting with .NET 9.0, TState can be a ref struct.

TResult CStringSequenceFunc<out TResult>(FixedCStringSequence)

Encapsulates a method that operates on a FixedCStringSequence instance and returns a value of type TResult.

TResult CStringSequenceFunc<in TArg, out TResult>(FixedCStringSequence, TArg)

Encapsulates a method that operates on a FixedCStringSequence instance, a state object of type TArg and returns a value of type TResult.

Note: Starting with .NET 9.0, TState can be a ref struct.

Buffers Delegates

These delegates encapsulate methods that operate on instances of managed buffers.

void ScopedBufferAction<T>(ScopedBuffer)

Encapsulates a method that receives a buffer of objects of type T.

Note: Starting with .NET 9.0, TState can be a ref struct.

void ScopedBufferAction<T, in TArg>(ScopedBuffer, TArg)

Encapsulates a method that receives a buffer of objects of type T and a state object of type TArg.

Note: Starting with .NET 9.0, TState can be a ref struct.

TResult ScopedBufferFunc<T, out TResult>(ScopedBuffer)

Encapsulates a function that receives a buffer of objects of type T and returns a result of type TResult.

TResult ScopedBufferFunc<T, in TArg, out TResult>(ScopedBuffer, TArg)

Encapsulates a method that receives a buffer of objects of type T, a state object of type TArg and returns a value of type TResult.

Note: Starting with .NET 9.0, TState can be a ref struct.


Enums

Rxmxnx.PInvoke.Extensions provides enums that simplify the classification of various types of values.

Iso639P1

Enumeration of ISO 639-1 (two letter) language codes.
CodeValueLanguage
Iv0x00.NET Invariant
Ab0x01Abkhazian
Aa0x02Afar
Af0x03Afrikaans
Ak0x04Akan
Sq0x05Albanian
Am0x06Amharic
Ar0x07Arabic
An0x08Aragonese
Hy0x09Armenian
As0x0AAssamese
Av0x0BAvaric
Ae0x0CAvestan
Ay0x0DAymara
Az0x0EAzerbaijani
Bm0x0FBambara
Ba0x10Bashkir
Eu0x11Basque
Be0x12Belaurian
Bn0x13Bengali
Bi0x14Bislama
Bs0x15Bosnian
Br0x16Breton
Bg0x17Bulgarian
My0x18Burmese
Ca0x19Catalan; Valencian
Ch0x1AChamorro
Ce0x1BChechen
Ny0x1CChichewa; Chewa; Nyanja
Zh0x1DChinese
Cv0x1EChuvash
Kw0x1FCornish
Co0x20Corsican
Cr0x21Cree
Cs0x22Czech
Da0x23Danish
Dv0x24Divehi; Dhivehi; Maldivian
Nl0x25Dutch; Flemish
Dz0x26Dzongkha
En0x27English
Eo0x28Esperanto
Et0x29Estonian
Ee0x2AEwe
Fo0x2BFaroese
Fj0x2CFijian
Fi0x2DFinnish
Fr0x2EFrench
Ff0x2FFulah
Gl0x30Galician
Ka0x31Georgian
De0x32German
El0x33Greek, Modern
Gn0x34Guarani
Gu0x35Gujarati
Ht0x36Haitian; Haitian Creole
Ha0x37Hausa
He0x38Hebrew
Hz0x39Herero
Hi0x3AHindi
Ho0x3BHiri Motu
Hu0x3CHungarian
Is0x3DIcelandic
Io0x3EIdo
Ig0x3FIgbo
Id0x40Indonesian
Ia0x41Interlingua
Ie0x42Interlingue
Iu0x43Inuktitut
Ik0x44Inupiaq
Ga0x45Irish
It0x46Italian
Ja0x47Japanese
Jv0x48Javanese
Kl0x49Kalaallisut
Kn0x4AKannada
Kr0x4BKanuri
Ks0x4CKashmiri
Kk0x4DKazakh
Ki0x4EKikuyu
Rw0x4FKinyarwanda
Ky0x50Kyrgyz
Kv0x51Komi
Kg0x52Kongo
Ko0x53Korean
Kj0x54Kuanyama
Ku0x55Kurdish
Lo0x56Lao
La0x57Latin
Lv0x58Latvian
Li0x59Limburgish
Ln0x5ALingala
Lt0x5BLithuanian
Lu0x5CLuba-Katanga
Lb0x5DLuxembourgish
Mk0x5EMacedonian
Mg0x5FMalagasy
Ms0x60Malay
Ml0x61Malayalam
Mt0x62Maltese
Gv0x63Manx
Mi0x64Maori
Mr0x65Marathi
Mh0x66Marshallese
Mn0x67Mongolian
Na0x68Nauru
Nv0x69Navajo
Ng0x6ANdonga
Ne0x6BNepali
Nd0x6CNorth Ndebele
Se0x6DNorthern Sami
No0x6ENorwegian
Nb0x6FNorwegian Bokmål
Nn0x70Norwegian Nynorsk
Ii0x71Nuosu
Oc0x72Occitan
Oj0x73Ojibwa
Or0x74Oriya
Om0x75Oromo
Os0x76Ossetian
Pa0x77Panjabi
Pi0x78Pali
Fa0x79Persian
Pl0x7APolish
Ps0x7BPashto
Pt0x7CPortuguese
Qu0x7DQuechua
Ro0x7ERomanian
Rm0x7FRomansh
Rn0x80Rundi
Ru0x81Russian
Sm0x82Samoan
Sg0x83Sango
Sa0x84Sanskrit
Sc0x85Sardinian
Gd0x86Scottish Gaelic
Sr0x87Serbian
Sn0x88Shona
Sd0x89Sindhi
Si0x8ASinhalese
Sk0x8BSlovak
Sl0x8CSlovenian
So0x8DSomali
St0x8ESouthern Sotho
Nr0x8FSouth Ndebele
Es0x90Spanish
Su0x91Sundanese
Sw0x92Swahili
Ss0x93Swati
Sv0x94Swedish
Tl0x95Tagalog
Ty0x96Tahitian
Tg0x97Tajik
Ta0x98Tamil
Tt0x99Tatar
Te0x9ATelugu
Th0x9BThai
Bo0x9CTibetan
Ti0x9DTigrinya
To0x9ETonga
Ts0x9FTsonga
Tn0xA0Tswana
Tr0xA1Turkish
Tk0xA2Turkmen
Tw0xA3Twi
Ug0xA4Uighur
Uk0xA5Ukrainian
Ur0xA6Urdu
Uz0xA7Uzbek
Ve0xA8Venda
Vi0xA9Vietnamese
Vo0xAAVolapük
Wa0xABWalloon
Cy0xACWelsh
Fy0xADWestern Frisian
Wo0xAEWolof
Xh0xAFXhosa
Yi0xB0Yiddish
Yo0xB1Yoruba
Za0xB2Zhuang
Zu0xB3Zulu

Structs

Rxmxnx.PInvoke.Extensions provides value types for the managed handling of references, fixed memory segments, and stack-allocated buffers

Pointers

These structures safely represent memory addresses for references or methods of a specific type.

ReadOnlyValPtr<T>

Represents a platform-specific type used to manage a pointer to a read-only value of type T.

Notes:

  • This struct implements IComparable, ISpanFormattable, ISerializable, IWrapper<IntPtr>, IEquatable<ReadOnlyValPtr<T>> and IComparable<ReadOnlyValPtr<T>> interfaces.
  • Starting with .NET 7.0, this struct implements IParsable<ReadOnlyValPtr<T>> interface.
  • Starting with .NET 9.0, T can be a ref struct.

Static Properties:

  • Zero A read-only field that represents a pointer that has been initialized to zero.
  • IsUnmanaged

    Indicates if T type is an unmanaged type.

Properties:

  • Pointer

    Internal pointer as an IntPtr.

  • IsZero

    Indicates whether the current pointer is null.

  • Reference A read-only reference to the value pointed to by this instance.

Methods:

  • GetUnsafeFixedReference(IDisposable?)

    Retrieves an unsafe IReadOnlyFixedReference<T>.IDisposable instance from current read-only reference pointer.

  • GetUnsafeFixedContext(IDisposable?)

    Retrieves an unsafe IReadOnlyFixedContext<T>.IDisposable instance from current read-only reference pointer.

    Note: In .NET 9.0 and later, invoking this method on an instance whose generic type argument is a ref struct will cause a runtime error.

ValPtr<T>

Represents a platform-specific type used to manage a pointer to a mutable value of type T.

Notes:

  • This struct implements IComparable, ISpanFormattable, ISerializable, IWrapper<IntPtr>, IEquatable<ValPtr<T>> and IComparable<ValPtr<T>> interfaces.
  • Starting with .NET 7.0, this struct implements IParsable<ValPtr<T>> interface.
  • Starting with .NET 9.0, T can be a ref struct.

Static Properties:

  • Zero A read-only field that represents a pointer that has been initialized to zero.
  • IsUnmanaged

    Indicates if T type is an unmanaged type.

Properties:

  • Pointer

    Internal pointer as an IntPtr.

  • IsZero Indicates whether the current pointer is `null`.
  • Reference A reference to the value pointed to by this instance.

Methods:

  • GetUnsafeFixedReference(IDisposable?)

    Retrieves an unsafe IReadOnlyFixedReference<T>.IDisposable instance from current reference pointer.

  • GetUnsafeFixedContext(IDisposable?)

    Retrieves an unsafe IReadOnlyFixedContext<T>.IDisposable instance from current reference pointer.

    Note: In .NET 9.0 and later, invoking this method on an instance whose generic type argument is a ref struct will cause a runtime error.

FuncPtr<TDelegate>

Represents a platform-specific type used to handle a pointer to a method of type TDelegate.

Note: This struct implements ISpanFormattable, ISerializable, IWrapper<IntPtr> and IEquatable<FuncPtr<T>> interfaces.

Static Properties:

  • Zero A read-only field representing a null-initialized function pointer.

Properties:

  • Pointer

    Internal pointer as an IntPtr.

  • IsZero Indicates whether the current pointer is `null`.
  • Invoke A managed delegate using the method address pointed to by this instance.

Note: Starting with .NET 7.0, these structs can be used with source-generated P/Invoke marshalling.

Fixed memory lists

These structures represent lists of fixed memory block addresses.

ReadOnlyFixedMemoryList

Represents a list of IReadOnlyFixedMemory instances.

Note: This type is a ref struct. Instances of current type can be used with foreach.

Properties:

  • Count Gets the total number of elements in the list.
  • IsEmpty Indicates whether the current list is empty.

Indexer:

  • Item

    Gets the IReadOnlyFixedMemory at the specified index.

Methods:

  • ToArray()

    Creates an array from the current ReadOnlyFixedMemoryList instance.

FixedMemoryList

Represents a list of IFixedMemory instances.

Note: This type is a ref struct. Instances of current type can be used with foreach.

Properties:

  • Count Gets the total number of elements in the list.
  • IsEmpty Indicates whether the current list is empty.

Indexer:

  • Item

    Gets the IFixedMemory at the specified index.

Methods:

  • ToArray()

    Creates an array from the current FixedMemoryList instance.

FixedCStringSequence

Represents a CStringSequence that is fixed in memory.

Note: This type is a ref struct. Instances of current type can be used with foreach.

Properties:

  • Values

    Gets the list of CString values in the sequence.

Indexer:

  • Item Gets the element at the given index in the sequence.

Methods:

  • ToArray()

    Creates an array of IReadOnlyFixedMemory instances from the current instance.

Managed buffer types

These structures represent managed buffers that can be stored on the stack.

Atomic<T>

Atomic binary buffer.

Note: This type represents the binary unit 20 space.

Composite<TBufferA, TBufferB,T>

Composite binary buffer.

Notes:

  • This type represents a composite binary buffer of size A + B.
  • TBufferA and TBufferB must be binary buffers.
  • TBufferB must always be a space of 2n.
  • TBufferA must be a buffer smaller than or equal to TBufferB.
  • If TBufferA and TBufferB are equal, the current type will represent a binary space of 2n + 1.
NonBinarySpace<TArray, T>

Non-binary buffer space.

Notes:

  • This type represents a non-binary buffer based on a custom structure TArray.
  • TArray and T must be compatible.
  • The size of this space is the amount of elements of type T can be stored in a TArray instance.
CStringSequence.Utf8View

A view over the UTF-8 items in a CStringSequence instance, allowing filtering of empty and null items.

Notes:

  • This type is a ref struct type. Instances of current type can be used with foreach.
  • The enumerator of this type is also a ref struct type.
  • The type of the enumeration of this type is ReadOnlySpan<Byte> items.
  • Each item in the enumeration is guaranteed to be null-terminated.
  • By default, the UTF-8 data is not pinned in memory. To pin it during enumeration, the source CStringSequence instance must be pinned, and the CString.Empty instance must also be pinned if the enumeration includes empty items.

Properties:

  • Source

    Enumeration source CStringSequence instance.

  • EmptyItemsIncluded

    Indicates whether current enumeration includes empty items from the source CStringSequence instance.

  • Count Gets the total number of elements in the current enumeration.
CStringSequence.Builder

A fluent builder for CStringSequence type.

Notes:

  • This type is a struct type. Please avoid boxing.
  • The builder is based on CStringBuilder type.
  • This type allows UTF-16 texts and UTF-8 escaped text as inputs.
  • Until 2.9.0 version Append, AppendEscaped, Insert, RemoveAt, Clear and Build methods and the Count property are thread-safe, in upper versions to make thread-safe operations use ConcurrentAppend, ConcurrentAppendEscaped, ConcurrentInsert, ConcurrentRemoveAt, ConcurrentClear, ConcurrentBuild and ConcurrentCount methods.

Properties:

  • Count Retrieves the number of items contained in the builder.

Methods:

  • Append(?) Appends the text input as the last item of the building sequence.

    Supported types include: CString, String, ReadOnlySpan<Byte>, ReadOnlySequence<Byte> and ReadOnlySpan<Char>.

  • AppendEscaped(?) Appends the unescaped text input as the last item of the building sequence.

    Supported types include: ReadOnlySpan<Byte> and ReadOnlySequence<Byte>.

  • Insert(Int32, ?) Inserts the text input at the given position of the building sequence.

    Supported types include: CString, String, ReadOnlySpan<Byte>, ReadOnlySequence<Byte> and ReadOnlySpan<Char>.

  • RemoveAt(Int32) Removes the item at the given position of the building sequence.
  • Clear() Removes all the items of the building sequence.
  • Build()

    Builds a new CStringSequence instance using the state of the builder.

  • ConcurrentCount() Retrieves the number of items contained in the builder. This method is thread-safe.
  • ConcurrentAppend(?) Appends the text input as the last item of the building sequence. This method is thread-safe.

    Supported types include: CString, String, ReadOnlySpan<Byte>, ReadOnlySequence<Byte> and ReadOnlySpan<Char>.

  • ConcurrentAppendEscaped(?) Appends the unescaped text input as the last item of the building sequence. This method is thread-safe.

    Supported types include: ReadOnlySpan<Byte> and ReadOnlySequence<Byte>.

  • ConcurrentInsert(Int32, ?) Inserts the text input at the given position of the building sequence. This method is thread-safe.

    Supported types include: CString, String, ReadOnlySpan<Byte>, ReadOnlySequence<Byte> and ReadOnlySpan<Char>.

  • ConcurrentRemoveAt(Int32) Removes the item at the given position of the building sequence. This method is thread-safe.
  • ConcurrentClear() Removes all the items of the building sequence. This method is thread-safe.
  • ConcurrentBuild()

    Builds a new CStringSequence instance using the state of the builder. This method is thread-safe.


Classes

Rxmxnx.PInvoke.Extensions provides reference types for the managed handling of UTF8/ASCII texts, memory regions, and metadata for stack-allocated buffer management.

ValueRegion<T>

This class represents a region of memory that contains a sequence of T values.

Note: This type does not allow public inheritance.

Properties:

  • IsMemorySlice Indicates whether the current instance represents a subregion of a memory region.

Indexer:

  • Item Retrieves an item from the memory region at the specified zero-based index.

Methods:

  • ToArray() Copies the contents of this memory region into a new array.
  • TryAlloc(GCHandleType, out GCHandle) Tries to create a new GC CHandle for current value region.
  • GetPinnable(out Int32) Retrieves the pinnable instance for current region.

Operators:

  • ReadOnlySpan<T>(ValueRegion<T>)

    Converts the value of the current ValueRegion<T> to its equivalent read-only span representation.

  • T[]?(ValueRegion<T>)

    Converts the value of the current ValueRegion<T> to its equivalent array representation.

Static Methods:

  • Create(T[])

    Creates a new ValueRegion<T> instance from an array of T values.

  • Create(IntPtr, Int32)

    Creates a new ValueRegion<T> instance from a pointer to a native memory region.

  • Create(ReadOnlySpanFunc<T>)

    Creates a new ValueRegion<T> instance from a ReadOnlySpanFunc<T> function.

  • Create<TState>(TState, ReadOnlySpanFunc<T, TState>)

    Creates a new ValueRegion<T> instance from a ReadOnlySpanFunc<T, TState> function and a TState instance.

  • Create<TState>(TState, ReadOnlySpanFunc<T, TState>, Func<TState, GCHandleType, GCHandle>>)

    Creates a new ValueRegion<T> instance from a ReadOnlySpanFunc<T, TState> function and a GC-allocatable instance.

Memory class

The nested abstract class Memory allows the creation of custom ValueRegion<T> types based on ReadOnlyMemory<T> instances.

BufferTypeMetadata

Represents the metadata of a managed buffer type.

Note: Implements IEnumerableSequence<BufferTypeMetadata>. This type does not allow public inheritance.

Properties:

  • IsBinary Indicates whether current type is binary space.
  • Size Buffer capacity.
  • IsBinary Number of components.
  • BufferType Buffer type.

Indexer:

  • Item Retrieves a component from current metadata at the specified zero-based index.

Generic class

BufferTypeMetadata<T> representing a generic BufferTypeMetadata object.

Note: Inherits from BufferTypeMetadata. This type does not allow public inheritance.

CString

Represents a sequence of UTF-8 encoded characters.

Notes:

  • Implements ICloneable, IComparable, IComparable<CString>, IComparable<String>, IEquatable<CString>, IEquatable<String> and IEnumerableSequence<Byte>.
  • This type is sealed.
  • The GetHashCode() produces the same hash code as a System.String instance with the equivalent UTF-16 text.
  • Instances of this type can be fixed but not pinned.
  • Instances of this type can be iterated using both IEnumerable<Byte> and ReadOnlySpan<Byte>.Enumerator.
  • Range operations can be used on instances of this type.
  • This type exposes APIs to Join, Concat and Compare CString instances.
  • This type exposes operators of comparison and equality of CString and String instances.
  • Starting with .NET 9.0, params is used with ReadOnlySpan<> arguments instead of [] arguments.
  • Starting with .NET 7.0, this type supports source-generated P/Invoke marshalling.
  • When marshalling, the instances of this type are represented as null-terminated UTF-8 strings.
  • Starting with .NET Core 3.0, the nested JsonConverter class can be used to support serialization and deserialization with System.Text.Json.
  • The JSON deserialization process produces null-terminated CString instances; however, it is not guaranteed that this termination consists of a single UTF-8 null character.
  • The nested abstract class Backing allows the creation of custom UTF-8 data storage to be backed by CString instances.

Static Fields:

  • Empty Represents an empty UTF-8 string. This field is read-only.
  • Zero Represents a null-pointer UTF-8 string. This field is read-only.

Properties:

  • IsNullTerminated

    Gets a value indicating whether the text in the current CString instance ends with a null-termination character.

  • IsReference

    Gets a value indicating whether the UTF-8 text is referenced by, and not contained within, the current CString instance.

  • IsSegmented

    Gets a value indicating whether the current CString instance is a segment (or slice) of another CString instance.

  • IsFunction

    Gets a value indicating whether the current CString instance is a function.

  • IsZero

    Gets a value indicating whether the current CString instance references to the null UTF-8 text.

Indexer:

  • Item

    Gets the Byte value at a specified position in the current CString object.

Constructors:

  • CString(Byte, Int32)

    Initializes a new instance of the CString class to the value indicated by a specified UTF-8 character repeated a specified number of times.

  • CString(Byte, Byte, Int32)

    Initializes a new instance of the CString class to the value indicated by a specified UTF-8 sequence repeated a specified number of times.

  • CString(Byte, Byte, Byte, Int32)

    Initializes a new instance of the CString class to the value indicated by a specified UTF-8 sequence repeated a specified number of times.

  • CString(Byte, Byte, Byte, Byte, Int32)

    Initializes a new instance of the CString class to the value indicated by a specified UTF-8 sequence repeated a specified number of times.

  • CString(ReadOnlySpan<Byte>)

    Initializes a new instance of the CString class using the UTF-8 characters indicated in the specified read-only span.

  • CString(ReadOnlySequence<Byte>)

    Initializes a new instance of the CString class using the UTF-8 characters indicated in the specified read-only sequence.

  • CString(ReadOnlySpanFunc<Byte>)

    Initializes a new instance of the CString class that contains the UTF-8 string returned by the specified ReadOnlySpanFunc<Byte>.

  • CString(Char, Int32)

    Initializes a new instance of the CString class to the value indicated by a specified UTF-16 character repeated a specified number of times.

  • CString(Char, Char, Int32)

    Initializes a new instance of the CString class to the value indicated by a specified UTF-16 sequence repeated a specified number of times.

  • CString(ReadOnlySpan<Char>)

    Initializes a new instance of the CString class using the UTF-16 characters indicated in the specified read-only span.

Methods:

  • ToArray()

    Copies the UTF-8 text of the current CString instance into a new byte array.

  • AsSpan()

    Retrieves the UTF-8 units of the current CString as a read-only span of bytes.

  • ToHexString()

    Returns a String that represents the current UTF-8 text as a hexadecimal value.

  • TryPin()

    Tries to pin the current UTF-8 memory block.

Operators:

  • CString?(Byte[]?)

    Defines an implicit conversion of a given Byte array to CString.

  • CString?(String?)

    Defines an explicit conversion of a given String to CString.

  • ReadOnlySpan<Byte>(CString?)

    Defines an implicit conversion of a given CString to a read-only span of bytes.

  • + CString

    Defines an operator for concatenating the current instance with a CString instance.

  • + String

    Defines an operator for concatenating the current instance with a String instance.

  • + ReadOnlySpan<Byte>

    Defines an operator for concatenating the current instance with a ReadOnlySpan<Byte> instance.

  • + ReadOnlySpan<Char>

    Defines an operator for concatenating the current instance with a ReadOnlySpan<Char> instance.

Notes:

  • The CString resulting from a concatenation operation is always a new null-terminated instance when both operands are non-empty.
  • If both operands in a concatenation operation are empty or null, the resulting instance is CString.Empty. Otherwise, the non-empty operand instance is returned.
  • Concatenation operations involving String or ReadOnlySpan<char> require converting UTF-16 text to UTF-8.

Static Methods:

  • IsNullOrEmpty(CString?)

    Determines whether the specified CString is null or an empty UTF-8 string.

  • Create(ReadOnlySpan<Byte>)

    Creates a new instance of the CString class using the UTF-8 characters provided in the specified read-only span.

  • Create(ReadOnlySpanFunc<Byte>?)

    Creates a new instance of the CString class using the ReadOnlySpanFunc<Byte> delegate provided.

  • Create(Byte[]?)

    Creates a new instance of the CString class using the binary internal information provided.

  • Create<TState>(TState)

    Creates a new instance of the CString class using a TState instance.

    Note: This method is available only on .NET 6.0 and later.

  • Create<TState>(TState, ReadOnlySpanFunc<Byte, TState>, Func<TState, GCHandleType, GCHandle>)

    Creates a new instance of the CString class using a TState instance.

  • CreateUnsafe(IntPtr, Int32, useFullLength)

    Creates a new instance of the CString class using the pointer to a UTF-8 character array and length provided.

  • CreateNullTerminatedUnsafe(IntPtr)

    Creates a new instance of the CString class using the pointer to a UTF-8 character null-terminated array.

  • IsImagePersistent(CString)

    Gets a value indicating whether the data of the given CString instance resides within the loaded binary image.

  • GetAssociatedSequence(CString?, out Int32)

    Tries to retrieve the CStringSequence instance and the index of the item associated to the given value.

  • Unescape(ReadOnlySpan<Byte>)

    Creates a new instance of the CString class using an unescaped copy of the given UTF-8 escaped text.

  • Unescape(ReadOnlySequence<Byte>)

    Creates a new instance of the CString class using an unescaped copy of the given UTF-8 escaped text.

  • GetHashCode(ReadOnlySpan<Byte>)

    Computes the hash code for the provided UTF-8 unit span.

    Note: As with GetHashCode(), On some restricted runtime environments, this method may require temporary string materialization to preserve System.String hash compatibility.

CStringSequence

Represents a sequence of null-terminated UTF-8 text strings.

Notes:

  • Implements ICloneable, IEquatable<CString>, IComparable<CStringSequence>, IReadOnlyList<CString> and IEnumerableSequence<CString>.
  • This type is sealed.
  • The instances of this type can be fixed but not pinned.
  • Range operations can be used on instances of this type.
  • This type exposes constructors to create sequences from up to 8 instances of ReadOnlySpan<Byte> in order to optimize memory usage.
  • Starting with .NET 9.0, params is used with ReadOnlySpan<> arguments instead of [] arguments.
  • Starting with .NET 7.0, this type supports source-generated P/Invoke marshalling.
  • When marshalling, instances of this type are represented as null-terminated arrays of null-terminated UTF-8 strings. Therefore, only non-empty items will be included.
  • Starting with .NET Core 3.0, the nested JsonConverter class can be used to support serialization and deserialization with System.Text.Json.
  • The nested ref struct Utf8View allows iteration over UTF-8 items represented as ReadOnlySpan<byte>, providing
  • control over whether empty elements are included during enumeration.
  • When marshalling in .NET 7.0 and later, Utf8View instances are represented as arrays of null-terminated UTF-8 strings. Empty elements are omitted only if they were not included in the enumeration view.
  • The nested struct Builder allows fluent creation of CStringSequence instances.

Static Properties:

  • Empty Represents an empty sequence.

Properties:

  • Count

    Gets the number of CString instances contained in this CStringSequence.

  • NonEmptyCount

    Gets the number of non-empty CString instances contained in the buffer of this CStringSequence.

Indexer:

  • Item

    Gets the CString at the specified index.

Constructors:

  • CStringSequence(params String?[])

    Initializes a new instance of the CStringSequence class from a collection of strings.

  • CStringSequence(params CString?[])

    Initializes a new instance of the CStringSequence class from a collection of UTF-8 strings.

  • CStringSequence(ReadOnlySpan<CString>)

    Initializes a new instance of the CStringSequence class from a read-only span of UTF-8 strings.

  • CStringSequence(ReadOnlySpan<String>)

    Initializes a new instance of the CStringSequence class from a read-only span of strings.

  • CStringSequence(IReadOnlySpan<String?>)

    Initializes a new instance of the CStringSequence class from a collection of strings.

  • CStringSequence(IReadOnlySpan<CString?>)

    Initializes a new instance of the CStringSequence class from a collection of UTF-8 strings.

Methods:

  • ToCString()

    Returns a CString that represents the current sequence. The returned CString is always null-terminated.

  • ToCString(Boolean)

    Returns a CString that represents the current sequence. The boolean parameter specifies whether the returned CString should be null-terminated. must be null-terminated.

  • Pin()

    Creates an MemoryHandle instance by pinning the current instance, allowing safe access to the fixed memory region.

  • GetFixedPointer()

    Creates an IFixedPointer.IDisposable instance by pinning the current instance, allowing safe access to the fixed memory region.

  • WithSafeTransform(CStringSequenceAction)

    Executes a specified action using the current instance treated as a FixedCStringSequence.

  • WithSafeTransform<TState>(TState, CStringSequenceAction)

    Executes a specified action on the current instance treated as a FixedCStringSequence, using an additional parameter passed to the action.

  • WithSafeTransform<TResult>(CStringSequenceFunc<TResult>)

    Executes a specified function using the current instance treated as a FixedCStringSequence.

  • WithSafeTransform<TState, TResult>(TState, CStringSequenceFunc<TResult>)

    Executes a specified function using the current instance treated as a FixedCStringSequence, and an additional parameter passed to the function.

  • GetOffsets(Span<Int32>)

    Fills the provided span with the starting byte offsets of each UTF-8 encoded CString segment within the current buffer.

  • TryGetIndex(CString?, out Int32)

    Attempts to retrieve the index of the item associated by instance with the specified CString.

Static Methods:

  • Create<TState>(TState, CStringSequenceCreationAction<TState>, params Int32?[]) Creates a new UTF-8 text sequence with specific lengths, and initializes each UTF-8 text string in it after creation using the specified callback.
  • Create(ReadOnlySpan<Byte>)

    Creates a new CStringSequence instance from a UTF-8 buffer.

  • Create(ReadOnlySpan<Char>)

    Creates a new CStringSequence instance from a UTF-8 buffer represented by a span of Char. This method is obsolete, use CStringSequence.Create(ReadOnlySpan<Byte> value) instead.

  • GetUnsafe(ReadOnlySpan<ReadOnlyValPtr<Byte>>)

    Creates a new CStringSequence instance from a UTF-8 null-terminated text pointer span.

  • Parse(String?)

    Converts the buffer of a UTF-8 sequence to a CStringSequence instance.

CStringBuilder

Represents a mutable string of UTF-8 encoded characters.

Notes:

  • This class cannot be inherited.
  • This type is designed to be a UTF-8 equivalent of System.Text.StringBuilder.
  • Instances of this type are mutable.
  • This type exposes APIs to append, insert, remove, and clear UTF-8 text efficiently.
  • This type supports method chaining (Fluent API) for most operations.
  • This type provides optimized support for ReadOnlySpan<Byte> and ReadOnlySpan<Char>, minimizing allocations during string manipulation.
  • Conversions to CString can be customized to produce null-terminated or non-null-terminated strings.
  • Until 2.9.0 version Append, AppendLine, AppendJoin, Insert, Remove, Clear, ToCString and ToString methods and the Length property are thread-safe, in upper versions to make thread-safe operations use ConcurrentAppend, ConcurrentAppendLine, ConcurrentAppendJoin, ConcurrentInsert, ConcurrentRemove, ConcurrentClear, ConcurrentToCString, ConcurrentToString and ConcurrentLength methods.

Properties:

  • Length

    Gets the length of the current CStringBuilder object.

Constructors:

  • CStringBuilder()

    Initializes a new instance of the CStringBuilder class.

  • CStringBuilder(UInt16)

    Initializes a new instance of the CStringBuilder class using the specified capacity.

  • CStringBuilder(CString?)

    Initializes a new instance of the CStringBuilder class using the specified value as initial content.

  • CStringBuilder(String?)

    Initializes a new instance of the CStringBuilder class using the specified value as initial content.

  • CStringBuilder(ReadOnlySpan<Byte>)

    Initializes a new instance of the CStringBuilder class using the specified UTF-8 text as initial content.

  • CStringBuilder(ReadOnlySpan<Char>)

    Initializes a new instance of the CStringBuilder class using the specified UTF-16 text as initial content.

Methods:

  • ToCString()

    Converts the value of this instance to a CString. The returned CString is always null-terminated.

  • ToCString(Boolean)

    Converts the value of this instance to a CString. The boolean parameter specifies whether the returned CString should be null-terminated.

  • ToString()

    Converts the value of this instance to a String.

  • CopyTo(Int32, Span<Byte>)

    Copies the UTF-8 characters from a specified segment of this instance to a destination span of bytes.

  • Clear()

    Removes all characters from the current CStringBuilder instance.

  • Remove(Int32, Int32)

    Removes the specified range of characters from this instance.

  • Append(?)

    Appends the UTF-8 string representation of a specified parameter to this instance.

    Supported types include: CString, String, ReadOnlySpan<Byte>, ReadOnlySequence<Byte>, ReadOnlySpan<Char>, Byte[], Char[] and standard numeric primitives.

  • AppendJoin(?, ?)

    Concatenates the string representations of the elements in the provided sequence, using the specified separator between each member.

    Supported separator types include: CString, and ReadOnlySpan<Byte>. Supported types include: CString[], ReadOnlySpan<CString>, CStringSequence, CStringSequence.Utf8View, and IEnumerable<CString>.

  • AppendLine()

    Appends the default line terminator to the end of the current CStringBuilder object.

  • AppendLine(?)

    Appends the UTF-8 string representation of a specified parameter followed by the default line terminator to the end of the current CStringBuilder object.

    Supported types include: CString, String, ReadOnlySpan<Byte>, ReadOnlySequence<Byte>, ReadOnlySpan<Char>, Byte[] and Char[].

  • Insert(Int32, ?)

    Inserts the UTF-8 string representation of a specified parameter into this instance at the specified character position.

    Supported types include: CString, String, ReadOnlySpan<Byte>, ReadOnlySpan<Char>, Byte[], Char[] and standard numeric primitives.

  • ConcurrentLength()

    Retrieves the length of the current CStringBuilder object. This method is thread-safe.

  • ConcurrentToCString()

    Converts the value of this instance to a CString. The returned CString is always null-terminated. This method is thread-safe.

  • ConcurrentToCString(Boolean)

    Converts the value of this instance to a CString. The boolean parameter specifies whether the returned CString should be null-terminated. This method is thread-safe.

  • ConcurrentCopyTo(Int32, Span<Byte>)

    Copies the UTF-8 characters from a specified segment of this instance to a destination span of bytes. This method is thread-safe.

  • ConcurrentClear()

    Removes all characters from the current CStringBuilder instance. This method is thread-safe.

  • ConcurrentRemove(Int32, Int32)

    Removes the specified range of characters from this instance. This method is thread-safe.

  • ConcurrentAppend(?)

    Appends the UTF-8 string representation of a specified parameter to this instance.

    Supported types include: CString, String, ReadOnlySpan<Byte>, ReadOnlySequence<Byte>, ReadOnlySpan<Char>, Byte[], Char[] and standard numeric primitives. This method is thread-safe.

  • ConcurrentAppendJoin(?, ?)

    Concatenates the string representations of the elements in the provided sequence, using the specified separator between each member. This method is thread-safe.

    Supported separator types include: CString, and ReadOnlySpan<Byte>. Supported types include: CString[], ReadOnlySpan<CString>, CStringSequence, CStringSequence.Utf8View, and IEnumerable<CString>.

  • ConcurrentAppendLine()

    Appends the default line terminator to the end of the current CStringBuilder object. This method is thread-safe.

  • ConcurrentAppendLine(?)

    Appends the UTF-8 string representation of a specified parameter followed by the default line terminator to the end of the current CStringBuilder object. This method is thread-safe.

    Supported types include: CString, String, ReadOnlySpan<Byte>, ReadOnlySequence<Byte>, ReadOnlySpan<Char>, Byte[] and Char[].

  • ConcurrentInsert(Int32, ?)

    Inserts the UTF-8 string representation of a specified parameter into this instance at the specified character position. This method is thread-safe.

    Supported types include: CString, String, ReadOnlySpan<Byte>, ReadOnlySpan<Char>, Byte[], Char[] and standard numeric primitives.


Extensions

Rxmxnx.PInvoke.Extensions provides static classes that expose APIs to facilitate the management of managed memory, pointer usage, and this package's internal resources.

BinaryExtensions

Set of useful methods when working with bytes, byte arrays, and byte spans in a PInvoke context.

  • ToValue<T>(this Byte[])

    Retrieves a T value from the given byte array.

    Note: ´T´ is ´unmanaged´.

  • ToValue<T>(this Span<Byte>)

    Retrieves a T value from the given byte span.

    Note: ´T´ is ´unmanaged´.

  • ToValue<T>(this ReadOnlySpan<Byte>)

    Retrieves a T value from the given read-only byte span.

    Note: ´T´ is ´unmanaged´.

  • AsValue<T>(this ReadOnlySpan<Byte>)

    Retrieves a read-only reference to a T value from the given read-only byte span.

    Note: ´T´ is ´unmanaged´.

  • AsValue<T>(this Span<Byte>)

    Retrieves a reference to a T value from the given byte span.

    Note: ´T´ is ´unmanaged´.

  • AsHexString(this Byte[]) Gets the hexadecimal string representation of a byte array.
  • AsHexString(this Byte) Gets the hexadecimal string representation of a byte.
  • WithSafeFixed(this Span<Byte>, FixedAction) Prevents the garbage collector from relocating the current span by pinning its memory address until the specified action has completed.
  • WithSafeFixed(this Span<Byte>, ReadOnlyFixedAction) Prevents the garbage collector from relocating the current span by pinning its memory address until the specified action has completed.
  • WithSafeFixed(this ReadOnlySpan<Byte>, ReadOnlyFixedAction) Prevents the garbage collector from relocating the current read-only span by pinning its memory address until the specified action has completed.
  • WithSafeFixed<TArg>(this Span<Byte>, FixedAction<TArg>) Prevents the garbage collector from relocating the current span by pinning its memory address until the specified action has completed.
  • WithSafeFixed<TArg>(this Span<Byte>, ReadOnlyFixedAction<TArg>) Prevents the garbage collector from relocating the current span by pinning its memory address until the specified action has completed.
  • WithSafeFixed<TArg>(this ReadOnlySpan<Byte>, ReadOnlyFixedAction<TArg>) Prevents the garbage collector from relocating the current read-only span by pinning its memory address until the specified action has completed.
  • WithSafeFixed<TResult>(this Span<Byte>, FixedFunc<TResult>) Prevents the garbage collector from relocating the current span by pinning its memory address until the specified function has completed.
  • WithSafeFixed<TResult>(this Span<Byte>, ReadOnlyFixedFunc<TResult>) Prevents the garbage collector from relocating the current span by pinning its memory address until the specified function has completed.
  • WithSafeFixed<TResult>(this ReadOnlySpan<Byte>, ReadOnlyFixedFunc<TResult>) Prevents the garbage collector from relocating the current read-only span by pinning its memory address until the specified function has completed.
  • WithSafeFixed<TArg, TResult>(this Span<Byte>, TArg, FixedFunc<TArg, TResult>) Prevents the garbage collector from relocating the current span by pinning its memory address until the specified function has completed.
  • WithSafeFixed<TArg, TResult>(this Span<Byte>, TArg, ReadOnlyFixedFunc<TArg, TResult>) Prevents the garbage collector from relocating the current span by pinning its memory address until the specified function has completed.
  • WithSafeFixed<TArg, TResult>(this ReadOnlySpan<Byte>, TArg, ReadOnlyFixedFunc<TArg, TResult>) Prevents the garbage collector from relocating the current read-only span by pinning its memory address until the specified function has completed.
DelegateExtensions

Additional functionality for working with delegates.

  • GetUnsafeFuncPtr<TDelegate>(this TDelegate)

    Creates a FuncPtr<TDelegate> from a memory reference to a TDelegate delegate instance.

  • GetUnsafeIntPtr<TDelegate>(this TDelegate)

    Retrieves an IntPtr from a memory reference to a TDelegate delegate instance.

  • GetUnsafeUIntPtr<TDelegate>(this TDelegate)

    Retrieves a UIntPtr from a memory reference to a TDelegate delegate instance.

  • WithSafeFixed<TDelegate>(this TDelegate, FixedMethodAction<TDelegate>) Prevents the garbage collector from relocating a delegate in memory and fixes its address while an action is being performed.
  • WithSafeFixed<TDelegate, TArg>(this TDelegate, TArg, FixedMethodAction<TDelegate, TArg>) Prevents the garbage collector from relocating a delegate in memory and fixes its address while an action is being performed, passing an additional argument to the action.
  • WithSafeFixed<TDelegate, TResult>(this TDelegate, TArg, FixedMethodFunc<TDelegate, TResult>)

    Prevents the garbage collector from relocating a delegate in memory, fixes its address, and invokes the function that returns a TResult value.

  • WithSafeFixed<TDelegate, TArg, TResult>(this TDelegate, TArg, FixedMethodFunc<TDelegate, TArg, TResult>)

    Prevents the garbage collector from relocating a delegate in memory, fixes its address, invokes the function that returns a TResult value, passing an additional argument to the function.

  • GetFixedMethod<TDelegate>(this TDelegate?)

    Creates an IFixedMethod<TDelegate>.IDisposable instance by marshalling the current TDelegate instance, ensuring a safe interop context.

  • IsImageMethod<TDelegate>(this TDelegate?)

    Determines whether all methods referenced by the specified delegate are backed by statically compiled image code rather than dynamically generated runtime code.

    Notes:

    • This API is primarily intended for Mono-based runtimes.
    • Returns false if the delegate is null or any referenced method is an open generic method.
    • On platforms without memory inspection support, detection may be unreliable and defaults to false.
    • In reflection-free runtimes, valid delegates are assumed to refer to image-backed code.
    • The entire invocation list of the delegate is evaluated; each delegate element represents a single method.
  • IsImageMethod(this MethodBase?)

    Determines whether the specified reflected method is backed by statically compiled image code rather than dynamically generated runtime code.

    Notes:

    • This API is primarily intended for Mono-based runtimes.
    • Returns false for null or open generic methods, or on platforms without memory inspection support.
MemoryBlockExtensions

Additional functionality for working with memory blocks.

  • IsLiteral<T>(this Span<T>)

    Indicates whether the given Span<T> instance represents a literal or hardcoded memory region.

    Note: This function is currently available only on Windows, Linux, macOS and FreeBSD.

  • IsLiteral<T>(this ReadOnlySpan<T>)

    Indicates whether the given ReadOnlySpan<T> instance represents a literal or hardcoded memory region.

    Note: This function is currently available only on Windows, Linux, macOS and FreeBSD.

  • MayBeNonLiteral<T>(this ReadOnlySpan<T>)

    Indicates whether the given ReadOnlySpan<T> instance represents memory that is not part of a hardcoded literal.

    Note: If the platform is unsupported or an inspection error occurs, the method returns true.

  • GetUnsafeValPtr<T>(this Span<T>)

    Retrieves an unsafe ValPtr<T> pointer from Span<T> instance.

  • GetUnsafeValPtr<T>(this ReadOnlySpan<T>)

    Retrieves an unsafe ValPtr<T> pointer from ReadOnlySpan<T> instance.

  • GetUnsafePtr<T>(this Span<T>)

    Retrieves an unsafe IntPtr pointer from Span<T> instance.

  • GetUnsafePtr<T>(this ReadOnlySpan<T>)

    Retrieves an unsafe IntPtr pointer from ReadOnlySpan<T> instance.

  • GetUnsafeUIntPtr<T>(this Span<T>)

    Retrieves an unsafe UIntPtr pointer from Span<T> instance.

  • GetUnsafeUIntPtr<T>(this ReadOnlySpan<T>)

    Retrieves an unsafe UIntPtr pointer from ReadOnlySpan<T> instance.

  • AsBytes<TSource>(this Span<TSource>)

    Reinterprets the span of TSource as a binary span.

    Note: TSource is unmanaged.

  • AsBytes<TSource>(this ReadOnlySpan<TSource>)

    Reinterprets the read-only span of TSource as a read-only binary span.

    Note: TSource is unmanaged.

  • AsValues<TSource, TDestination>(this Span<TSource>)

    Reinterprets the span of TSource as a span of TDestination.

    Note: TSource is unmanaged. TDestination is unmanaged.

  • AsValues<TSource, TDestination>(this ReadOnlySpan<TSource>)

    Reinterprets the read-only span of TSource as a read-only span of TDestination.

    Note: TSource is unmanaged. TDestination is unmanaged.

  • AsValues<TSource, TDestination>(this Span<TSource>, Span<Byte>)

    Reinterprets the span of TSource as a span of TDestination.

    Note: TSource is unmanaged. TDestination is unmanaged.

  • AsValues<TSource, TDestination>(this Span<TSource>, ReadOnlySpan<Byte>)

    Reinterprets the span of TSource as a read-only span of TDestination.

    Note: TSource is unmanaged. TDestination is unmanaged.

  • AsValues<TSource, TDestination>(this ReadOnlySpan<TSource>, ReadOnlySpan<Byte>)

    Reinterprets the read-only span of TSource as a read-only span of TDestination.

    Note: TSource is unmanaged. TDestination is unmanaged.

  • GetFixedContext<T>(this ReadOnlyMemory<T>)

    Creates an IReadOnlyFixedContext<T>.IDisposable instance by pinning the current ReadOnlyMemory<T> instance, ensuring a safe context for accessing the fixed memory.

    Note: T is unmanaged.

  • GetFixedContext<T>(this Memory<T>)

    Creates an IFixedContext<T>.IDisposable instance by pinning the current Memory<T> instance, ensuring a safe context for accessing the fixed memory.

    Note: T is unmanaged.

  • GetFixedMemory<T>(this ReadOnlyMemory<T>)

    Creates an IReadOnlyFixedMemory<T>.IDisposable instance by pinning the current ReadOnlyMemory<T> instance, ensuring a safe context for accessing the fixed memory.

    Note: T is unmanaged.

  • GetFixedMemory<T>(this Memory<T>)

    Creates an IFixedMemory<T>.IDisposable instance by pinning the current Memory<T> instance, ensuring a safe context for accessing the fixed memory.

    Note: T is unmanaged.

  • AsReadOnlySpan<T>(this T[]?) Creates a new read-only span over a target array.
  • AsCovariantSpan<T>(this T[]?) Creates a new covariant span over a target array.
  • AsMemory<T>(this T[...]) Creates a new memory region over the target array.
  • AsSpan<T>(this T[...]) Creates a new span over a target array.
  • WithSafeFixed<T>(this Span<T>, FixedContextAction<T>) Prevents the garbage collector from relocating the current span by pinning its memory address until the specified action has completed.
  • WithSafeFixed<T>(this Span<T>, ReadOnlyFixedContextAction<T>) Prevents the garbage collector from relocating the current span by pinning its memory address until the specified action has completed.
  • WithSafeFixed<T>(this ReadOnlySpan<T>, ReadOnlyFixedContextAction<T>) Prevents the garbage collector from relocating the current read-only span by pinning its memory address until the specified action has completed.
  • WithSafeFixed<T, TArg>(this Span<T>, FixedContextAction<T, TArg>) Prevents the garbage collector from relocating the current span by pinning its memory address until the specified action has completed.
  • WithSafeFixed<T, TArg>(this Span<T>, ReadOnlyFixedContextAction<T, TArg>) Prevents the garbage collector from relocating the current span by pinning its memory address until the specified action has completed.
  • WithSafeFixed<T, TArg>(this ReadOnlySpan<T>, ReadOnlyFixedContextAction<T, TArg>) Prevents the garbage collector from relocating the current read-only span by pinning its memory address until the specified action has completed.
  • WithSafeFixed<T, TResult>(this Span<T>, FixedContextFunc<T, TResult>) Prevents the garbage collector from relocating the current span by pinning its memory address until the specified function has completed.
  • WithSafeFixed<T, TResult>(this Span<T>, ReadOnlyFixedContextFunc<T, TResult>) Prevents the garbage collector from relocating the current span by pinning its memory address until the specified function has completed.
  • WithSafeFixed<T, TResult>(this ReadOnlySpan<T>, ReadOnlyFixedContextFunc<T, TResult>) Prevents the garbage collector from relocating the current read-only span by pinning its memory address until the specified function has completed.
  • WithSafeFixed<T, TArg, TResult>(this Span<T>, TArg, FixedContextFunc<T, TArg, TResult>) Prevents the garbage collector from relocating the current span by pinning its memory address until the specified function has completed.
  • WithSafeFixed<T, TArg, TResult>(this Span<T>, TArg, ReadOnlyFixedContextFunc<T, TArg, TResult>) Prevents the garbage collector from relocating the current span by pinning its memory address until the specified function has completed.
  • WithSafeFixed<T, TArg, TResult>(this ReadOnlySpan<T>, TArg, ReadOnlyFixedContextFunc<T, TArg, TResult>) Prevents the garbage collector from relocating the current read-only span by pinning its memory address until the specified function has completed.
PointerExtensions

Set of extensions for basic operations with IntPtr and UIntPtr instances.

  • IsZero(this IntPtr)

    Determines if the IntPtr instance is zero.

  • IsZero(this UIntPtr)

    Determines if the UIntPtr instance is zero.

  • ToUIntPtr(this IntPtr)

    Converts the specified IntPtr instance to a UIntPtr instance.

  • ToUIntPtr(this MemoryHandle) Converts the specified `MemoryHandle` instance to a `UIntPtr` instance.
  • ToIntPtr(this UIntPtr)

    Converts the specified UIntPtr instance to a IntPtr instance.

  • ToIntPtr(this MemoryHandle)

    Converts the specified MemoryHandle instance to a IntPtr instance.

  • GetUnsafeString(this IntPtr)

    Generates a String instance from the memory at the given IntPtr, interpreting the contents as UTF-16 text.

  • GetUnsafeString(this UIntPtr)

    Generates a String instance from the memory at the given UIntPtr, interpreting the contents as UTF-16 text.

  • GetUnsafeString(this MemoryHandle)

    Generates a String instance from the memory at the given MemoryHandle, interpreting the contents as UTF-16 text.

  • GetUnsafeString(this IntPtr, Int32)

    Generates a String instance from the memory at the given IntPtr, interpreting the contents as UTF-16 text.

  • GetUnsafeString(this UIntPtr, Int32)

    Generates a String instance from the memory at the given UIntPtr, interpreting the contents as UTF-16 text.

  • GetUnsafeString(this MemoryHandle, Int32)

    Generates a String instance from the memory at the given MemoryHandle, interpreting the contents as UTF-16 text.

  • GetUnsafeArray<T>(this IntPtr, Int32)

    Generates a T array by copying values from memory starting at the location referenced by an IntPtr.

    Note: ´T´ is ´unmanaged´.

  • GetUnsafeArray<T>(this UIntPtr, Int32)

    Generates a T array by copying values from memory starting at the location referenced by a UIntPtr.

    Note: ´T´ is ´unmanaged´.

  • GetUnsafeArray<T>(this MemoryHandle, Int32)

    Generates a T array by copying values from memory starting at the location referenced by a MemoryHandle.

    Note: ´T´ is ´unmanaged´.

  • GetUnsafeSpan<T>(this IntPtr, Int32)

    Generates a Span<T> instance from an IntPtr, interpreting the memory at the specified location as a sequence of unmanaged values.

    Note: ´T´ is ´unmanaged´.

  • GetUnsafeSpan<T>(this UIntPtr, Int32)

    Generates a Span<T> instance from a UIntPtr, interpreting the memory at the specified location as a sequence of unmanaged values.

    Note: ´T´ is ´unmanaged´.

  • GetUnsafeSpan<T>(this MemoryHandle, Int32)

    Generates a Span<T> instance from a MemoryHandle, interpreting the memory at the specified location as a sequence of unmanaged values.

    Note: ´T´ is ´unmanaged´.

  • GetUnsafeReadOnlySpan<T>(this IntPtr, Int32)

    Generates a ReadOnlySpan<T> instance from an IntPtr, interpreting the memory at the specified location as a sequence of unmanaged values.

    Note: ´T´ is ´unmanaged´.

  • GetUnsafeReadOnlySpan<T>(this UIntPtr, Int32)

    Generates a ReadOnlySpan<T> instance from a UIntPtr, interpreting the memory at the specified location as a sequence of unmanaged values.

    Note: ´T´ is ´unmanaged´.

  • GetUnsafeReadOnlySpan<T>(this MemoryHandle, Int32)

    Generates a ReadOnlySpan<T> instance from a MemoryHandle, interpreting the memory at the specified location as a sequence of unmanaged values.

    Note: ´T´ is ´unmanaged´.

  • GetUnsafeDelegate<TDelegate>(this IntPtr)

    Generates a delegate of type TDelegate from an IntPtr.

  • GetUnsafeDelegate<TDelegate>(this UIntPtr)

    Creates a delegate of type TDelegate from a UIntPtr.

  • GetUnsafeReference<T>(this IntPtr)

    Generates a memory reference to an unmanaged value of type T from IntPtr.

  • GetUnsafeReference<T>(this UIntPtr)

    Generates a memory reference to an unmanaged value of type T from UIntPtr.

  • GetUnsafeReadOnlyReference<T>(this IntPtr)

    Generates a read-only memory reference to an unmanaged value of type T from IntPtr.

  • GetUnsafeReadOnlyReference<T>(this UIntPtr)

    Generates a read-only memory reference to an unmanaged value of type T from UIntPtr.

  • GetUnsafeReadOnlySpanFromNullTerminated(this ReadOnlyValPtr<Char>)

    Generates a read-only span for a UTF-16 null-terminated string from ReadOnlyValPtr<Char>.

  • GetUnsafeReadOnlySpanFromNullTerminated(this ReadOnlyValPtr<Byte>)

    Generates a read-only span for a UTF-8 null-terminated string from ReadOnlyValPtr<Byte>.

  • IsImageCode(this RuntimeMethodHandle) Determines whether the specified method handle represents executable code that is backed by a statically compiled image rather than dynamically generated runtime code.

    Notes:

    • This API is primarily intended for Mono-based runtimes.
    • Returns false for open generic methods and on platforms that do not support memory inspection.
PointerCStringExtensions

Set of extensions for CString operations with IntPtr and UIntPtr instances.

  • GetUnsafeCString(this IntPtr, Int32)

    Generates a CString instance using the memory reference pointed to by the given IntPtr, considering it as the start of a UTF-8 encoded string.

  • GetUnsafeCString(this UIntPtr, Int32)

    Generates a CString instance using the memory reference pointed to by the given UIntPtr, considering it as the start of a UTF-8 encoded string.

  • GetUnsafeCString(this MemoryHandle, Int32)

    Generates a CString instance using the memory reference pointed to by the given MemoryHandle, considering it as the start of a UTF-8 encoded string.

Utf8ViewExtensions

Set of extensions for CStringSequence viewing operations.

  • CreateView(this CStringSequence?, Boolean)

    Creates a new CStringSequence.Utf8View from the given CStringSequenceinstance, with an additional parameter to control the inclusion of empty items in the resulting enumeration.

    Note: This extension method can be safely called on null instances of CStringSequence; it does not throw a NullReferenceException.

ReferenceExtensions

Set of extensions for basic operations with references to unmanaged values.

  • GetUnsafeValPtr<T>(ref this T)

    Obtains an unsafe pointer of type ValPtr<T> from a reference to an unmanaged value of type T.

  • GetUnsafeIntPtr<T>(ref this T)

    Obtains an unsafe pointer of type IntPtr from a reference to an unmanaged value of type T.

  • GetUnsafeUIntPtr<T>(ref this T)

    Obtains an unsafe pointer of type UIntPtr from a reference to an unmanaged value of type T.

  • Transform<TSource, TDestination>(ref this TSource)

    Generates a reference for an unmanaged value of type TDestination from an existing reference to an unmanaged value of type TSource.

  • AsBytes<TSource>(ref this TSource)

    Creates a Span<Byte> from a reference to an unmanaged value of type TSource.

  • WithSafeFixed<T>(ref this T, FixedReferenceAction<T>) Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided action.
  • WithSafeFixed<T>(ref this T, ReadOnlyFixedReferenceAction<T>) Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided read-only action.
  • WithSafeFixed<T, TArg>(ref this T, TArg, FixedReferenceAction<T, TArg>) Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided action along with an argument.
  • WithSafeFixed<T, TArg>(ref this T, TArg, ReadOnlyFixedReferenceAction<T, TArg>) Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided read-only action along with an argument.
  • WithSafeFixed<T, TResult>(ref this T, FixedReferenceFunc<T, TResult>) Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided function.
  • WithSafeFixed<T, TResult>(ref this T, ReadOnlyFixedReferenceFunc<T, TResult>) Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided read-only function.
  • WithSafeFixed<T, TArg, TResult>(ref this T, TArg, FixedReferenceFunc<T, TArg, TResult>) Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided function along with an argument.
  • WithSafeFixed<T, TArg, TResult>(ref this T, TArg, ReadOnlyFixedReferenceFunc<T, TArg, TResult>) Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided read-only function along with an argument.
StringExtensions

Set of extensions for basic operations with String instances.

  • WithSafeFixed(this String?, ReadOnlyFixedContextAction<Char>) Pins the current string to prevent the garbage collector from relocating its memory address during the execution of the specified action.
  • WithSafeFixed<TArg>(this String?, TArg, ReadOnlyFixedContextAction<Char, TArg>) Pins the current string to prevent the garbage collector from relocating its memory address during the execution of the specified action along with an argument.
  • WithSafeFixed<TResult>(this String?, ReadOnlyFixedContextFunc<Char, TResult>) Pins the current string to prevent the garbage collector from relocating its memory address during the execution of the specified function.
  • WithSafeFixed<TArg, TResult>(this String?, TArg, ReadOnlyFixedContextFunc<Char, TArg, TResult>) Pins the current string to prevent the garbage collector from relocating its memory address during the execution of the specified function along with an argument.
UnmanagedValueExtensions

Set of extensions for basic operations with unmanaged values.

  • RentFixed<T>(this ArrayPool<T>, Int32, Boolean)

    Rents and pins an array of minimum number of T elements from given array pool, ensuring a safe context for accessing the fixed memory.

  • RentFixed<T>(this ArrayPool<T>, Int32, Boolean, out Int32)

    Rents and pins an array of minimum number of T elements from given array pool, ensuring a safe context for accessing the fixed memory.

  • ToBytes<T>(this T)

    Converts a given unmanaged value of type T into an array of Byte.

  • ToBytes<TSource>(this TSource[]?)

    Converts an array of unmanaged values of type TSource into an array of Byte.

  • ToValues<TSource, TDestination>(this TSource[]?)

    Converts an array of unmanaged values of type TSource into an array of another unmanaged value type TDestination.

  • ToValues<TSource, TDestination>(this TSource[]?, out Byte[]?)

    Converts an array of unmanaged values of type TSource into an array of another unmanaged value type TDestination and provides the residual binary array of the reinterpretation.

  • GetName<TEnum>(this TEnum) Retrieves the name of the constant in the specified enumeration type that has the specified value.
  • WithSafeFixed<T>(ref this T, FixedReferenceAction<T>) Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided action.
  • WithSafeFixed<T>(ref this T, ReadOnlyFixedReferenceAction<T>) Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided read-only action.
  • WithSafeFixed<T, TArg>(ref this T, TArg, FixedReferenceAction<T, TArg>) Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided action along with an argument.
  • WithSafeFixed<T, TArg>(ref this T, TArg, ReadOnlyFixedReferenceAction<T, TArg>) Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided read-only action along with an argument.
  • WithSafeFixed<T, TResult>(ref this T, FixedReferenceFunc<T, TResult>) Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided function.
  • WithSafeFixed<T, TResult>(ref this T, ReadOnlyFixedReferenceFunc<T, TResult>) Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided read-only function.
  • WithSafeFixed<T, TArg, TResult>(ref this T, TArg, FixedReferenceFunc<T, TArg, TResult>) Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided function along with an argument.
  • WithSafeFixed<T, TArg, TResult>(ref this T, TArg, ReadOnlyFixedReferenceFunc<T, TArg, TResult>) Temporarily fixes the location of a reference by preventing the garbage collector from moving it and executes a provided read-only function along with an argument.

Utilities

Rxmxnx.PInvoke.Extensions provides static classes that complement the APIs facilitating the management of read-only managed memory, enable interaction with the runtime environment, and allow the use of the package's internal resources.

AotInfo

Provides information about the Ahead-of-Time compilation.

Static Properties:

  • IsReflectionDisabled Indicates whether runtime reflection is disabled.
  • IsCodeGenerationSupported Indicates whether the current runtime supports the emission of dynamic IL code.
  • IsPlatformTrimmed Indicates whether the current runtime is trimmed for the current platform.

    Note: Starting with .NET 5.0, this property enables trimming by allowing the linker to remove unreachable code.

  • IsNativeAot Indicates whether the current runtime is NativeAOT.

    Notes:

    • Starting with .NET 6.0, this property helps the linker remove unreachable code on desktop and mobile XNU platforms.
    • On mobile XNU platforms, this property is always considered true.
    • On CoreCLR-based runtimes (including R2R, NativeAOT, and NativeAOT-LLVM), detection of AOT is reliable and does not require memory inspection.
    • On Mono-based runtimes, AOT detection may depend on when and where the property is first accessed, since Mono AOT does not compile the entire assembly at once and requires platform memory inspection to confirm AOT execution.
    • On Blazor WebAssembly (Mono-based), it is generally not possible to distinguish AOT from non-AOT runtimes; this property may only return true when IL generation is disallowed.
SystemInfo

Provides information about the runtime system.

Static Properties:

  • IsMonoRuntime Indicates whether the current runtime is Mono.
  • IsWebRuntime Indicates whether the current runtime is Web.

    Note: Starting with .NET 8.0, this property enables trimming by allowing the linker to remove unreachable code.

  • IsWindows Indicates whether the current runtime is running on a Windows System.

    Note: Starting with .NET 5.0, this property enables trimming by allowing the linker to remove unreachable code.

  • IsLinux Indicates whether the current runtime is running on a Linux System.

    Note: Starting with .NET 5.0, this property enables trimming by allowing the linker to remove unreachable code.

  • IsMac Indicates whether the current runtime is running on a macOS System.

    Note: Starting with .NET 6.0, this property enables trimming by allowing the linker to remove unreachable code.

  • IsFreeBsd Indicates whether the current runtime is running on a FreeBSD System.

    Note: Starting with .NET 5.0, this property enables trimming by allowing the linker to remove unreachable code.

  • IsNetBsd Indicates whether the current runtime is running on a NetBSD System.
  • IsSolaris Indicates whether the current runtime is running on a Solaris System.

Static Methods:

  • IsOsPlatform(String?) Indicates whether the current runtime is running on the specified platform.
  • IsOsPlatform(String?[]) Indicates whether the current runtime is running on one of the specified platforms.
  • IsOsPlatform(ReadOnlySpan<String?>) Indicates whether the current runtime is running on one of the specified platforms.

Note: Starting with .NET 9.0, params is used with ReadOnlySpan<String?> arguments instead of String?[] arguments.

BufferManager

This class allows to allocate buffers on stack if possible.

Static Properties:

  • BufferAutoCompositionEnabled Indicates whether metadata for any required buffer is auto-composed.

    Note: This property will always be false if compiled with IlcDisableReflection=true or if the PInvoke.DisableBufferAutoComposition feature switch is enabled.

  • MaxBinarySize Maximum supported binary buffer size at runtime.

    Note: This property always returns UInt16.MaxValue on platforms where runtime capacity limits are unsupported. On .NET 8.0 and later, its value may be affected by the PInvoke.BootstrapBufferStorage.Minimal, PInvoke.BootstrapBufferStorage.Medium, PInvoke.BootstrapBufferStorage.Limited feature switches.

Static Methods:

  • Alloc<T>(UInt16, ScopedBufferAction<T>, Boolean)

    Allocates a buffer with count elements and executes action.

  • Alloc<T, TState>(UInt16, TState, ScopedBufferAction<T, TState>, Boolean)

    Allocates a buffer with count elements and executes action.

  • Alloc<T, TResult>(UInt16, ScopedBufferFunc<T, TResult>, Boolean)

    Allocates a buffer with count elements and executes func.

  • Alloc<T, TState, TResult>(UInt16, TState, ScopedBufferFunc<T, TState, TResult>, Boolean)

    Allocates a buffer with count elements and executes func.

  • Register<TBuffer>() Registers object buffer.

    Note: TBuffer is struct and IManagedBuffer<Object>.

  • Register<T, TBuffer>()

    Registers T buffer.

    Note: T is struct. TBuffer is struct and IManagedBuffer<T>.

  • RegisterNullable<T, TBuffer>()

    Registers T? buffer.

    Note: T is struct. TBuffer is struct and IManagedBuffer<T?>.

  • PrepareBinaryBuffer(UInt16) Prepares the binary buffer metadata needed to allocate given number of objects.

    Note: Reflection is always used by this method, and the buffer auto-Composition feature must be enabled.

  • PrepareBinaryBuffer<T>(UInt16)

    Prepares the binary buffer metadata needed to allocate given number of T items.

    Note: T is struct. Reflection is always used by this method, and the buffer auto-Composition feature must be enabled.

  • PrepareBinaryBufferNullable<T>()

    Prepares the binary buffer metadata needed to allocate given number of T? items.

    Note: T is struct. Reflection is always used by this method, and BufferAutoCompositionEnabled must be enabled.

Note: The nested static class VisualBasic provides VB.NET-compatible Alloc methods. These are designed to accommodate language constraints in Visual Basic and are not recommended for use in other .NET languages, due to minor performance overhead.

NativeUtilities

Set of utilities for exchange data within the P/Invoke context.

Static Fields:

  • PointerSize Size in bytes of a memory pointer.
  • GlobalizationInvariantModeEnabled Indicates whether globalization-invariant mode is enabled.

    Note: This property enables trimming by allowing the linker to remove unreachable code.

  • UserInterfaceIso639P1

    Retrieves the Iso639P1 enum value corresponding to the current user interface culture.

Static Methods:

  • SizeOf<T>()

    Gets the memory size of T structure.

    Note: T is unmanaged.

  • LoadNativeLib(String?, DllImportSearchPath?) Provides a high-level API for loading a native library.

    Note: This method is available only on .NET Core 3.0 and later.

  • LoadNativeLib(String?, ref EventHandler?, DllImportSearchPath?) Provides a high-level API for loading a native library.

    Note: This method is available only on .NET Core 3.0 and later.

  • GetNativeMethod<TDelegate>(IntPtr, String?)

    Gets the TDelegate delegate of an exported symbol.

    Note: This method is available only on .NET Core 3.0 and later.

  • GetNativeMethod<TDelegate>(IntPtr, String?)

    Gets a function pointer of type TDelegate of an exported symbol.

    Note: This method is available only on .NET Core 3.0 and later.

  • GetIso639P1(CultureInfo)

    Retrieves the Iso639P1 enum value corresponding to the specified culture.

  • GetUnsafeFuncPtr<TDelegate>(TDelegate)

    Creates an FuncPtr<TDelegate> from a memory reference to a TDelegate delegate instance.

  • GetUnsafeValPtr<T>(in T)

    Retrieves an unsafe ReadOnlyValPtr<T> pointer from a read-only reference to a T value.

    Note: Starting with .NET 9.0, T can be a ref struct.

  • GetUnsafeValPtrFromRef<T>(ref T)

    Retrieves an unsafe pointer of type ValPtr<T> from a reference to a value of type T.

    Note: Starting with .NET 9.0, T can be a ref struct.

  • GetUnsafeIntPtr<T>(in T)

    Retrieves an unsafe IntPtr pointer from a read-only reference to a T unmanaged value.

  • GetUnsafeUIntPtr<T>(in T)

    Retrieves an unsafe UIntPtr pointer from a read-only reference to a T unmanaged value.

  • Transform<TSource, TDestination>(in TSource)

    Transforms a read-only reference of an unmanaged value of type TSource into a read-only reference of an unmanaged value of type TDestination.

  • TransformReference<TSource, TDestination>(ref TSource)

    Transforms a reference of an unmanaged value of type TSource into a reference of an unmanaged value of type TDestination.

  • ToBytes<T>(in TSource)

    Retrieves a Byte array from a read-only reference to a TSource value.

    Note: TSource is unmanaged.

  • AsBytes<TSource>(in TSource)

    Creates a ReadOnlySpan<Byte> from an exising read-only reference to a TSource unmanaged value.

  • AsBinarySpan<TSource>(ref TSource)

    Creates a Span<Byte> from an exising reference to a TSource value.

    Note: TSource is unmanaged.

  • CreateArray<T, TState>(Int32, TState, SpanAction<T, TState>)

    Creates a new T array with a specific length and initializes it after creation by using the specified callback.

    Note: T is unmanaged.

  • CopyBytes<T>(in TSource, Span<Byte>, Int32)

    Performs a binary copy of the given TSource to the destination span.

    Note: TSource is unmanaged.

  • GetEnumValuesSpan<TEnum>()

    Creates a new span over an array of the values of the constants in a specified enumeration type.

    Note: TEnum is System.Enum.

  • GetEnumNamesSpan<TEnum>()

    Creates a new span over an array of the names of the constants in a specified enumeration type.

    Note: TEnum is System.Enum.

  • GetValuesFixedContext<TEnum>()

    Creates a new IReadOnlyFixedContext<TEnum>.IDisposable instance by pinning an array of the values of the constants in a specified enumeration type.

    Note: TEnum is System.Enum.

  • WithSafeReadOnlyFixed<T>(ref T, ReadOnlyFixedReferenceAction<T>)

    Prevents the garbage collector from relocating a given reference and fixes its memory address until action finishes.

    Note: Starting with .NET 9.0, T can be a ref struct.

  • WithSafeReadOnlyFixed<T, TArg>(ref T, TArg, ReadOnlyFixedReferenceAction<T, TArg>)

    Prevents the garbage collector from relocating a given reference and fixes its memory address until action finishes.

    Note: Starting with .NET 9.0, both T and TArg can be ref struct types.

  • WithSafeReadOnlyFixed<T, TResult>(ref T, ReadOnlyFixedReferenceFunc<T, TResult>)

    Prevents the garbage collector from relocating a given reference and fixes its memory address until func finishes.

    Note: Starting with .NET 9.0, T can be a ref struct.

  • WithSafeReadOnlyFixed<T, TArg, TResult>(ref T, TArg, ReadOnlyFixedReferenceFunc<T, TArg, TResult>)

    Prevents the garbage collector from relocating a given reference and fixes its memory address until func finishes.

    Note: Starting with .NET 9.0, both T and TArg can be ref struct types.

  • WithSafeFixed<T>(in T, ReadOnlyFixedReferenceAction<T>)

    Prevents the garbage collector from relocating a given read-only reference and fixes its memory address until action finishes.

    Note: Starting with .NET 9.0, T can be a ref struct.

  • WithSafeFixed<T>(ref T, FixedReferenceAction<T>)

    Prevents the garbage collector from relocating a given reference and fixes its memory address until action finishes.

    Note: Starting with .NET 9.0, T can be a ref struct.

  • WithSafeFixed<T, TArg>(in T, TArg, ReadOnlyFixedReferenceAction<T, TArg>)

    Prevents the garbage collector from relocating a given read-only reference and fixes its memory address until action finishes.

    Note: Starting with .NET 9.0, both T and TArg can be ref struct types.

  • WithSafeFixed<T, TArg>(ref T, TArg, FixedReferenceAction<T, TArg>)

    Prevents the garbage collector from relocating a given reference and fixes its memory address until action finishes.

    Note: Starting with .NET 9.0, both T and TArg can be ref struct types.

  • WithSafeFixed<T, TResult>(in T, ReadOnlyFixedReferenceFunc<T, TResult>)

    Prevents the garbage collector from relocating a given read-only reference and fixes its memory address until func finishes.

    Note: Starting with .NET 9.0, T can be a ref struct.

  • WithSafeFixed<T, TResult>(ref T, FixedReferenceFunc<T, TResult>)

    Prevents the garbage collector from relocating a given reference and fixes its memory address until func finishes.

    Note: Starting with .NET 9.0, T can be a ref struct.

  • WithSafeFixed<T, TArg, TResult>(in T, TArg, ReadOnlyFixedReferenceFunc<T, TArg, TResult>)

    Prevents the garbage collector from relocating a given read-only reference and fixes its memory address until func finishes.

    Note: Starting with .NET 9.0, both T and TArg can be ref struct types.

  • WithSafeFixed<T, TArg, TResult>(ref T, TArg, FixedReferenceFunc<T, TArg, TResult>)

    Prevents the garbage collector from relocating a given reference and fixes its memory address until func finishes.

    Note: Starting with .NET 9.0, both T and TArg can be ref struct types.

  • WithSafeFixed<TDelegate>(TDelegate, FixedMethodAction<TDelegate>) Prevents the garbage collector from relocating a given method delegate and fixes its memory address until action finishes.
  • WithSafeFixed<TDelegate, TArg>(TDelegate, TArg, FixedMethodAction<TDelegate, TArg>)

    Prevents the garbage collector from relocating a given method delegate and fixes its memory address until action finishes.

    Note: Starting with .NET 9.0, TArg can be a ref struct.

  • WithSafeFixed<TDelegate, TResult>(TDelegate, FixedMethodFunc<TDelegate, TResult>) Prevents the garbage collector from relocating a given method delegate and fixes its memory address until func finishes.
  • WithSafeFixed<TDelegate, TArg, TResult>(TDelegate, TArg, FixedMethodFunc<TDelegate, TArg, TResult>)

    Prevents the garbage collector from relocating a given method delegate and fixes its memory address until func finishes.

    Note: Starting with .NET 9.0, TArg can be a ref struct.

  • WithSafeFixed<T0, ..., T7>(Span<T0>, ..., Span<T7>, FixedListAction) Prevents the garbage collector from reallocating given spans and fixes their memory addresses until action completes.
  • WithSafeFixed<T0, ..., T7, TArg>(Span<T0>, ..., Span<T7>, TArg, FixedListAction<TArg>)

    Prevents the garbage collector from reallocating given spans and fixes their memory addresses until action completes.

    Note: Starting with .NET 9.0, TArg can be a ref struct.

  • WithSafeFixed<T0, ..., T7>(ReadOnlySpan<T0>, ..., ReadOnlySpan<T7>, ReadOnlyFixedListAction) Prevents the garbage collector from reallocating given spans and fixes their memory addresses until action completes.
  • WithSafeFixed<T0, ..., T7, TArg>(ReadOnlySpan<T0>, ..., ReadOnlySpan<T7>, TArg, ReadOnlyFixedListAction<TArg>)

    Prevents the garbage collector from reallocating given spans and fixes their memory addresses until action completes.

    Note: Starting with .NET 9.0, TArg can be a ref struct.

  • WithSafeFixed<T0, ..., T7, TResult>(Span<T0>, ..., Span<T7>, FixedListFunc<TResult>) Prevents the garbage collector from reallocating given spans and fixes their memory addresses until func completes.
  • WithSafeFixed<T0, ..., T7, TArg, TResult>(Span<T0>, ..., Span<T7>, TArg, FixedListFunc<TArg, TResult>)

    Prevents the garbage collector from reallocating given spans and fixes their memory addresses until func completes.

    Note: Starting with .NET 9.0, TArg can be a ref struct.

  • WithSafeFixed<T0, ..., T7, TResult>(ReadOnlySpan<T0>, ..., ReadOnlySpan<T7>, ReadOnlyFixedListFunc<TResult>) Prevents the garbage collector from reallocating given spans and fixes their memory addresses until func completes.
  • WithSafeFixed<T0, ..., T7, TArg, TResult>(Span<T0>, ..., Span<T7>, TArg, ReadOnlyFixedListFunc<TArg, TResult>)

    Prevents the garbage collector from reallocating given spans and fixes their memory addresses until func completes.

    Note: Starting with .NET 9.0, TArg can be a ref struct.

  • WithSafeReadOnlyFixed<T0, ..., T7>(Span<T0>, ..., Span<T7>, ReadOnlyFixedListAction) Prevents the garbage collector from reallocating given spans and fixes their memory addresses until action completes.
  • WithSafeReadOnlyFixed<T0, ..., T7, TArg>(Span<T0>, ..., Span<T7>, TArg, ReadOnlyFixedListAction<TArg>)

    Prevents the garbage collector from reallocating given spans and fixes their memory addresses until action completes.

    Note: Starting with .NET 9.0, TArg can be a ref struct.

  • WithSafeReadOnlyFixed<T0, ..., T7, TResult>(Span<T0>, ..., Span<T7>, ReadOnlyFixedListFunc<TResult>) Prevents the garbage collector from reallocating given spans and fixes their memory addresses until func completes.
  • WithSafeReadOnlyFixed<T0, ..., T7, TArg, TResult>(Span<T0>, ..., Span<T7>, TArg, ReadOnlyFixedListFunc<TArg, TResult>)

    Prevents the garbage collector from reallocating given spans and fixes their memory addresses until func completes.

    Note: Starting with .NET 9.0, TArg can be a ref struct.

  • GetFixedMethod<TDelegate>(TDelegate?)

    Creates an IFixedMethod<TDelegate>.IDisposable instance by marshalling the current TDelegate instance, ensuring a safe interop context.

  • IsImageMethod<TDelegate>(TDelegate?)

    Determines whether all methods referenced by the specified delegate are backed by statically compiled image code rather than dynamically generated runtime code.

    Notes:

    • This API is primarily intended for Mono-based runtimes.
    • Returns false if the delegate is null or any referenced method is an open generic method.
    • On platforms without memory inspection support, detection may be unreliable and defaults to false.
    • In reflection-free runtimes, valid delegates are assumed to refer to image-backed code.
    • The entire invocation list of the delegate is evaluated; each delegate element represents a single method.
  • HeapAlloc<T>(Int32)

    Allocates a native heap memory block and exposes it through an owning IFixedContext<T>.IDisposable instance.

    Note: T is unmanaged.


License

This project is licensed under the MIT License, one of the most permissive and widely-used open-source licenses.

Key Highlights:

  • Freedom of Use: The package can be used in both open-source and closed-source projects without restrictions.
  • Modification and Distribution: You are free to modify, distribute, and even sublicense the software as needed.
  • Attribution: The only requirement is to include the original copyright notice and license text in any copies or substantial portions of the software.

Disclaimer:

The software is provided "as is," without warranty of any kind. The authors are not liable for any damages or issues that may arise from its use.

For more details, refer to the full license text included in the LICENSE file.


Contributing

We warmly welcome contributions to this open-source project! Whether you're here to report issues, propose enhancements, or contribute directly to the codebase, your help is greatly appreciated.

For more details, refer to the CONTRIBUTING file.

Translations

We currently support only a few languages, but we are open to adding more! If you'd like to help with translations, please open an issue or reach out to us. Your contributions to expanding the project's accessibility are highly valued.

This library currently supports translations for the following languages:

  • English
  • Arabic
  • Chinese
  • French
  • German
  • Italian
  • Japanese
  • Portuguese
  • Russian
  • Spanish

Collaboration Guidelines

When contributing, please be respectful and constructive. We aim to create an inclusive and welcoming environment for everyone.

Thank you for considering contributing to this project! Your involvement, whether through reporting, coding, or translating, helps make this project better for everyone. 🚀