- Description
- Getting Started
- Abstractions
- Enums
- Structs
- Classes
- Extensions
- Utilities
- License
- Contributing
Rxmxnx.PInvoke.Extensions is a comprehensive library designed to streamline and enhance the
interaction between .NET and native P/Invoke methods.
- 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
Install the library via NuGet:
dotnet add package Rxmxnx.PInvoke.ExtensionsNote: 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.
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.Unsafe5.0System.Collections.Immutable5.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.Json5.0.2
.NET Core 3.1 — Legacy
- Inherits from .NET Core 3.0
- Updated Dependencies:
System.Runtime.CompilerServices.Unsafe6.0System.Collections.Immutable6.0System.Text.Json6.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.Unsafe6.1.2System.Collections.Immutable8.0System.Text.Json8.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
- AOT detection should be performed via reflection. Retrieving references to multidimensional array data should be done using static delegates, and managed buffer registration should be handled through buffer allocation.
- Uses CoreCLR implementations from .NET 6.0. Simpler alternatives may be substituted in .NET Standard 2.1.
- Internally relies on
Enum.GetName(Type, Object). - Value-type pointers support
ref structgenerics, but due to C# compiler restrictions, some methods must be implemented in IL.
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:
- Native AOT detection when targeting .NET 5.0 or earlier.
Starting with .NET 7.0, the use of reflection can be completely avoided.
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.
Rxmxnx.PInvoke.Extensions provides abstractions for managed handling of references and
fixed memory segments.
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,
Tcan be aref struct.
-
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>andIEquatable<IReferenceable<T>>. - This type allows public implementation or inheritance.
- Starting with .NET 9.0,
Tcan be aref struct.
-
Reference
Gets the reference to the instance of an object of type
T.
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.
-
Value
The wrapped
Tobject.
-
Create(T?)
Creates a new instance of an object that implements
IWrapper<T>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.
-
Create<TValue>(TValue)
Creates a new instance of an object that implements
IWrapper<TValue>interface.Note:
TValuegeneric type isstruct. -
CreateNullable<TValue>(TValue?)
Creates a new instance of an object that implements
IWrapper<TValue?>interface.Note:
TValuegeneric type isstruct. -
CreateObject<TObject>(TObject)
Creates a new instance of an object that implements
IWrapper<TObject>interface.Note:
TObjectgeneric type is areference 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.
-
Value
The wrapped
Tobject.
-
Create(T?)
Creates a new instance of an object that implements
IMutableWrapper<T>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.
-
Create<TValue>(TValue)
Creates a new instance of an object that implements
IMutableWrapper<TValue>interface.Note:
TValuegeneric type isstruct. -
CreateNullable<TValue>(TValue?)
Creates a new instance of an object that implements
IMutableWrapper<TValue?>interface.Note:
TValuegeneric type isstruct. -
CreateObject<TObject>(TObject)
Creates a new instance of an object that implements
IMutableWrapper<TObject>interface.Note:
TObjectgeneric type is areference 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.
-
Reference
Reference to
Twrapped instance.
-
Create(T?)
Creates a new instance of an object that implements
IMutableReference<T>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.
-
Create<TValue>(TValue)
Creates a new instance of an object that implements
IMutableReference<TValue>interface.Note:
TValuegeneric type isstruct. -
CreateNullable<TValue>(TValue?)
Creates a new instance of an object that implements
IMutableReference<TValue?>interface.Note:
TValuegeneric type isstruct. -
CreateObject<TObject>(TObject)
Creates a new instance of an object that implements
IMutableReference<TObject>interface.Note:
TObjectgeneric type is areference type.
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.
-
Pointer
Gets the pointer to the fixed block of memory.
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.
-
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.
-
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.
-
AsBinaryContext()
Creates a new instance of
IReadOnlyFixedContext<Byte>from the current instance. -
AsObjectContext()
Creates a new instance of
IReadOnlyFixedContext<Object>from the current instance.
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.
-
ValuePointer
Gets the value pointer to the read-only fixed block of memory. -
Values
Gets a read-only
Tspan over the fixed block of memory.
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.
-
Bytes
Gets a binary span over the fixed block of memory. -
Objects
Gets an object span over the fixed block of memory.
-
AsBinaryContext()
Creates a new instance of
IFixedContext<Byte>from the current instance. -
AsObjectContext()
Creates a new instance of
IFixedContext<Object>from the current instance.
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.
-
ValuePointer
Gets the value pointer to the fixed block of memory. -
Values
Gets a
Tspan over the fixed block of memory.
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.
-
Transformation(out IReadOnlyFixedMemory)
Reinterprets the read-only
Tfixed memory reference as a read-onlyTDestinationmemory reference.
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.
-
Transformation(out IFixedMemory)
Reinterprets the
Tfixed memory reference as aTDestinationmemory reference. -
Transformation(out IReadOnlyFixedMemory)
Reinterprets the
Tfixed memory reference as aTDestinationmemory reference.
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.
-
Transformation(out IReadOnlyFixedMemory)
Reinterprets the
Tfixed memory block asTDestinationmemory block.
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.
-
Transformation(out IFixedMemory)
Reinterprets the
Tfixed memory block as aTDestinationmemory block. -
Transformation(out IReadOnlyFixedMemory)
Reinterprets the `T` fixed memory block as a `TDestination` memory block.
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.
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,
Tcan be aref struct.
-
GetItem(Int32)
Retrieves the element at the specified index. -
GetSize()
Retrieves the total number of elements in the sequence.
-
DisposeEnumeration(Int32)
Method to call when
IEnumerator<T>is disposing.Note: This method is not available in .NET Standard 2.1 library.
-
CreateEnumerator(IEnumerableSequence<T>, Action<IEnumerableSequence<T>gt;?)
This static method allows the creation of an internal
IEnumerator<T>instance using anIEnumerableSequence<T>. TheActiondelegate 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:
TSelfgeneric type isstruct. This type allows public implementation or inheritance.- This type is available only on .NET 7.0 and later.
-
Alloc
Function that allocates a state instance.
-
IsNullTerminated
Indicates whether resulting UTF-8 text is null-terminated.
-
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.
-
GetMetadata<TBuffer>()
Retrieves the
BufferTypeMetadata<T>instance fromTBuffer.
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.
-
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.
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.
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.
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.
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.
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.
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.
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.
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.
Rxmxnx.PInvoke.Extensions provides enums that simplify the classification of various types of values.
Enumeration of ISO 639-1 (two letter) language codes.
| Code | Value | Language |
|---|---|---|
| Iv | 0x00 | .NET Invariant |
| Ab | 0x01 | Abkhazian |
| Aa | 0x02 | Afar |
| Af | 0x03 | Afrikaans |
| Ak | 0x04 | Akan |
| Sq | 0x05 | Albanian |
| Am | 0x06 | Amharic |
| Ar | 0x07 | Arabic |
| An | 0x08 | Aragonese |
| Hy | 0x09 | Armenian |
| As | 0x0A | Assamese |
| Av | 0x0B | Avaric |
| Ae | 0x0C | Avestan |
| Ay | 0x0D | Aymara |
| Az | 0x0E | Azerbaijani |
| Bm | 0x0F | Bambara |
| Ba | 0x10 | Bashkir |
| Eu | 0x11 | Basque |
| Be | 0x12 | Belaurian |
| Bn | 0x13 | Bengali |
| Bi | 0x14 | Bislama |
| Bs | 0x15 | Bosnian |
| Br | 0x16 | Breton |
| Bg | 0x17 | Bulgarian |
| My | 0x18 | Burmese |
| Ca | 0x19 | Catalan; Valencian |
| Ch | 0x1A | Chamorro |
| Ce | 0x1B | Chechen |
| Ny | 0x1C | Chichewa; Chewa; Nyanja |
| Zh | 0x1D | Chinese |
| Cv | 0x1E | Chuvash |
| Kw | 0x1F | Cornish |
| Co | 0x20 | Corsican |
| Cr | 0x21 | Cree |
| Cs | 0x22 | Czech |
| Da | 0x23 | Danish |
| Dv | 0x24 | Divehi; Dhivehi; Maldivian |
| Nl | 0x25 | Dutch; Flemish |
| Dz | 0x26 | Dzongkha |
| En | 0x27 | English |
| Eo | 0x28 | Esperanto |
| Et | 0x29 | Estonian |
| Ee | 0x2A | Ewe |
| Fo | 0x2B | Faroese |
| Fj | 0x2C | Fijian |
| Fi | 0x2D | Finnish |
| Fr | 0x2E | French |
| Ff | 0x2F | Fulah |
| Gl | 0x30 | Galician |
| Ka | 0x31 | Georgian |
| De | 0x32 | German |
| El | 0x33 | Greek, Modern |
| Gn | 0x34 | Guarani |
| Gu | 0x35 | Gujarati |
| Ht | 0x36 | Haitian; Haitian Creole |
| Ha | 0x37 | Hausa |
| He | 0x38 | Hebrew |
| Hz | 0x39 | Herero |
| Hi | 0x3A | Hindi |
| Ho | 0x3B | Hiri Motu |
| Hu | 0x3C | Hungarian |
| Is | 0x3D | Icelandic |
| Io | 0x3E | Ido |
| Ig | 0x3F | Igbo |
| Id | 0x40 | Indonesian |
| Ia | 0x41 | Interlingua |
| Ie | 0x42 | Interlingue |
| Iu | 0x43 | Inuktitut |
| Ik | 0x44 | Inupiaq |
| Ga | 0x45 | Irish |
| It | 0x46 | Italian |
| Ja | 0x47 | Japanese |
| Jv | 0x48 | Javanese |
| Kl | 0x49 | Kalaallisut |
| Kn | 0x4A | Kannada |
| Kr | 0x4B | Kanuri |
| Ks | 0x4C | Kashmiri |
| Kk | 0x4D | Kazakh |
| Ki | 0x4E | Kikuyu |
| Rw | 0x4F | Kinyarwanda |
| Ky | 0x50 | Kyrgyz |
| Kv | 0x51 | Komi |
| Kg | 0x52 | Kongo |
| Ko | 0x53 | Korean |
| Kj | 0x54 | Kuanyama |
| Ku | 0x55 | Kurdish |
| Lo | 0x56 | Lao |
| La | 0x57 | Latin |
| Lv | 0x58 | Latvian |
| Li | 0x59 | Limburgish |
| Ln | 0x5A | Lingala |
| Lt | 0x5B | Lithuanian |
| Lu | 0x5C | Luba-Katanga |
| Lb | 0x5D | Luxembourgish |
| Mk | 0x5E | Macedonian |
| Mg | 0x5F | Malagasy |
| Ms | 0x60 | Malay |
| Ml | 0x61 | Malayalam |
| Mt | 0x62 | Maltese |
| Gv | 0x63 | Manx |
| Mi | 0x64 | Maori |
| Mr | 0x65 | Marathi |
| Mh | 0x66 | Marshallese |
| Mn | 0x67 | Mongolian |
| Na | 0x68 | Nauru |
| Nv | 0x69 | Navajo |
| Ng | 0x6A | Ndonga |
| Ne | 0x6B | Nepali |
| Nd | 0x6C | North Ndebele |
| Se | 0x6D | Northern Sami |
| No | 0x6E | Norwegian |
| Nb | 0x6F | Norwegian Bokmål |
| Nn | 0x70 | Norwegian Nynorsk |
| Ii | 0x71 | Nuosu |
| Oc | 0x72 | Occitan |
| Oj | 0x73 | Ojibwa |
| Or | 0x74 | Oriya |
| Om | 0x75 | Oromo |
| Os | 0x76 | Ossetian |
| Pa | 0x77 | Panjabi |
| Pi | 0x78 | Pali |
| Fa | 0x79 | Persian |
| Pl | 0x7A | Polish |
| Ps | 0x7B | Pashto |
| Pt | 0x7C | Portuguese |
| Qu | 0x7D | Quechua |
| Ro | 0x7E | Romanian |
| Rm | 0x7F | Romansh |
| Rn | 0x80 | Rundi |
| Ru | 0x81 | Russian |
| Sm | 0x82 | Samoan |
| Sg | 0x83 | Sango |
| Sa | 0x84 | Sanskrit |
| Sc | 0x85 | Sardinian |
| Gd | 0x86 | Scottish Gaelic |
| Sr | 0x87 | Serbian |
| Sn | 0x88 | Shona |
| Sd | 0x89 | Sindhi |
| Si | 0x8A | Sinhalese |
| Sk | 0x8B | Slovak |
| Sl | 0x8C | Slovenian |
| So | 0x8D | Somali |
| St | 0x8E | Southern Sotho |
| Nr | 0x8F | South Ndebele |
| Es | 0x90 | Spanish |
| Su | 0x91 | Sundanese |
| Sw | 0x92 | Swahili |
| Ss | 0x93 | Swati |
| Sv | 0x94 | Swedish |
| Tl | 0x95 | Tagalog |
| Ty | 0x96 | Tahitian |
| Tg | 0x97 | Tajik |
| Ta | 0x98 | Tamil |
| Tt | 0x99 | Tatar |
| Te | 0x9A | Telugu |
| Th | 0x9B | Thai |
| Bo | 0x9C | Tibetan |
| Ti | 0x9D | Tigrinya |
| To | 0x9E | Tonga |
| Ts | 0x9F | Tsonga |
| Tn | 0xA0 | Tswana |
| Tr | 0xA1 | Turkish |
| Tk | 0xA2 | Turkmen |
| Tw | 0xA3 | Twi |
| Ug | 0xA4 | Uighur |
| Uk | 0xA5 | Ukrainian |
| Ur | 0xA6 | Urdu |
| Uz | 0xA7 | Uzbek |
| Ve | 0xA8 | Venda |
| Vi | 0xA9 | Vietnamese |
| Vo | 0xAA | Volapük |
| Wa | 0xAB | Walloon |
| Cy | 0xAC | Welsh |
| Fy | 0xAD | Western Frisian |
| Wo | 0xAE | Wolof |
| Xh | 0xAF | Xhosa |
| Yi | 0xB0 | Yiddish |
| Yo | 0xB1 | Yoruba |
| Za | 0xB2 | Zhuang |
| Zu | 0xB3 | Zulu |
Rxmxnx.PInvoke.Extensions provides value types for the managed handling of references, fixed memory segments, and
stack-allocated buffers
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>>andIComparable<ReadOnlyValPtr<T>>interfaces. - Starting with .NET 7.0, this struct implements
IParsable<ReadOnlyValPtr<T>>interface. - Starting with .NET 9.0,
Tcan be aref struct.
-
Zero
A read-only field that represents a pointer that has been initialized to zero. -
IsUnmanaged
Indicates if
Ttype is anunmanagedtype.
-
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.
-
GetUnsafeFixedReference(IDisposable?)
Retrieves an unsafe
IReadOnlyFixedReference<T>.IDisposableinstance from current read-only reference pointer. -
GetUnsafeFixedContext(IDisposable?)
Retrieves an unsafe
IReadOnlyFixedContext<T>.IDisposableinstance 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 structwill 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>>andIComparable<ValPtr<T>>interfaces. - Starting with .NET 7.0, this struct implements
IParsable<ValPtr<T>>interface. - Starting with .NET 9.0,
Tcan be aref struct.
-
Zero
A read-only field that represents a pointer that has been initialized to zero. -
IsUnmanaged
Indicates if
Ttype is anunmanagedtype.
-
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.
-
GetUnsafeFixedReference(IDisposable?)
Retrieves an unsafe
IReadOnlyFixedReference<T>.IDisposableinstance from current reference pointer. -
GetUnsafeFixedContext(IDisposable?)
Retrieves an unsafe
IReadOnlyFixedContext<T>.IDisposableinstance from current reference pointer.Note: In .NET 9.0 and later, invoking this method on an instance whose generic type argument is a
ref structwill 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.
-
Zero
A read-only field representing a null-initialized function pointer.
-
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.
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.
-
Count
Gets the total number of elements in the list. -
IsEmpty
Indicates whether the current list is empty.
-
Item
Gets the
IReadOnlyFixedMemoryat the specified index.
-
ToArray()
Creates an array from the current
ReadOnlyFixedMemoryListinstance.
FixedMemoryList
Represents a list of IFixedMemory instances.
Note: This type is a ref struct. Instances of current type can be used with foreach.
-
Count
Gets the total number of elements in the list. -
IsEmpty
Indicates whether the current list is empty.
-
Item
Gets the
IFixedMemoryat the specified index.
-
ToArray()
Creates an array from the current
FixedMemoryListinstance.
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.
-
Values
Gets the list of
CStringvalues in the sequence.
-
Item
Gets the element at the given index in the sequence.
-
ToArray()
Creates an array of
IReadOnlyFixedMemoryinstances from the current instance.
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.
TBufferAandTBufferBmust be binary buffers.TBufferBmust always be a space of 2n.TBufferAmust be a buffer smaller than or equal toTBufferB.- If
TBufferAandTBufferBare 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. TArrayandTmust be compatible.- The size of this space is the amount of elements of type
Tcan be stored in aTArrayinstance.
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 structtype. Instances of current type can be used withforeach. - The enumerator of this type is also a
ref structtype. - 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
CStringSequenceinstance must be pinned, and theCString.Emptyinstance must also be pinned if the enumeration includes empty items.
-
Source
Enumeration source
CStringSequenceinstance. -
EmptyItemsIncluded
Indicates whether current enumeration includes empty items from the source
CStringSequenceinstance. -
Count
Gets the total number of elements in the current enumeration.
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.
-
IsMemorySlice
Indicates whether the current instance represents a subregion of a memory region.
-
Item
Retrieves an item from the memory region at the specified zero-based index.
-
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.
-
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.
-
Create(T[])
Creates a new
ValueRegion<T>instance from an array ofTvalues. -
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 aReadOnlySpanFunc<T>function. -
Create<TState>(TState, ReadOnlySpanFunc<T, TState>)
Creates a new
ValueRegion<T>instance from aReadOnlySpanFunc<T, TState>function and a TState instance. -
Create<TState>(TState, ReadOnlySpanFunc<T, TState>, Func<TState, GCHandleType, GCHandle>>)
Creates a new
ValueRegion<T>instance from aReadOnlySpanFunc<T, TState>function and a GC-allocatable instance.
BufferTypeMetadata
Represents the metadata of a managed buffer type.
Note: Implements IEnumerableSequence<BufferTypeMetadata>. This type does not allow public inheritance.
-
IsBinary
Indicates whether current type is binary space. -
Size
Buffer capacity. -
IsBinary
Number of components. -
BufferType
Buffer type.
-
Item
Retrieves a component from current metadata at the specified zero-based index.
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>andIEnumerableSequence<Byte>. - This type is sealed.
- Instances of this type can be fixed but not pinned.
- Instances of this type can be iterated using both
IEnumerable<Byte>andReadOnlySpan<Byte>.Enumerator. - Range operations can be used on instances of this type.
- This type exposes APIs to Join, Concat and Compare
CStringinstances. - This type exposes operators of comparison and equality of
CStringandStringinstances. - Starting with .NET 9.0,
paramsis used withReadOnlySpan<>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
JsonConverterclass can be used to support serialization and deserialization withSystem.Text.Json.
-
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.
-
IsNullTerminated
Gets a value indicating whether the text in the current
CStringinstance 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
CStringinstance. -
IsSegmented
Gets a value indicating whether the current
CStringinstance is a segment (or slice) of anotherCStringinstance. -
IsFunction
Gets a value indicating whether the current
CStringinstance is a function. -
IsZero
Gets a value indicating whether the current
CStringinstance references to the null UTF-8 text.
-
Item
Gets the
Bytevalue at a specified position in the currentCStringobject.
-
CString(Byte, Int32)
Initializes a new instance of the
CStringclass 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
CStringclass 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
CStringclass 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
CStringclass 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
CStringclass using the UTF-8 characters indicated in the specified read-only span. -
CString(ReadOnlySpanFunc<Byte>)
Initializes a new instance of the
CStringclass that contains the UTF-8 string returned by the specifiedReadOnlySpanFunc<Byte>.
-
ToArray()
Copies the UTF-8 text of the current
CStringinstance into a new byte array. -
AsSpan()
Retrieves the UTF-8 units of the current
CStringas a read-only span of bytes. -
ToHexString()
Returns a
Stringthat represents the current UTF-8 text as a hexadecimal value. -
TryPin()
Tries to pin the current UTF-8 memory block.
-
CString?(Byte[]?)
Defines an implicit conversion of a given
Bytearray toCString. -
CString?(String?)
Defines an explicit conversion of a given
StringtoCString. -
ReadOnlySpan<Byte>(CString?)
Defines an implicit conversion of a given
CStringto a read-only span of bytes.
-
IsNullOrEmpty(CString?)
Determines whether the specified
CStringisnullor an empty UTF-8 string. -
Create(ReadOnlySpan<Byte>)
Creates a new instance of the
CStringclass using the UTF-8 characters provided in the specified read-only span. -
Create(ReadOnlySpanFunc<Byte>?)
Creates a new instance of the
CStringclass using theReadOnlySpanFunc<Byte>delegate provided. -
Create(Byte[]?)
Creates a new instance of the
CStringclass using the binary internal information provided. -
CreateCreate<TState>(TState)
Creates a new instance of the
CStringclass using aTStateinstance.Note: This method is available only on .NET 6.0 and later.
-
CreateCreate<TState>(TState, ReadOnlySpanFunc<Byte, TState>, Func<TState, GCHandleType, GCHandle>)
Creates a new instance of the
CStringclass using aTStateinstance. -
CreateUnsafe(IntPtr, Int32, useFullLength)
Creates a new instance of the
CStringclass using the pointer to a UTF-8 character array and length provided. -
CreateNullTerminatedUnsafe(IntPtr)
Creates a new instance of the
CStringclass using the pointer to a UTF-8 character null-terminated array.
CStringSequence
Represents a sequence of null-terminated UTF-8 text strings.
Notes:
- Implements
ICloneable,IEquatable<CString>,IComparable<CStringSequence>,IReadOnlyList<CString>andIEnumerableSequence<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,
paramsis used withReadOnlySpan<>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
JsonConverterclass can be used to support serialization and deserialization withSystem.Text.Json. - The nested
ref structUtf8Viewallows iteration over UTF-8 items represented asReadOnlySpan<byte>, providing - control over whether empty elements are included during enumeration.
- When marshalling in .NET 7.0 and later,
Utf8Viewinstances are represented as arrays of null-terminated UTF-8 strings. Empty elements are omitted only if they were not included in the enumeration view.
-
Empty
Represents an empty sequence.
-
Count
Gets the number of
CStringinstances contained in thisCStringSequence. -
NonEmptyCount
Gets the number of non-empty
CStringinstances contained in the buffer of thisCStringSequence.
-
Item
Gets the
CStringat the specified index.
-
CStringSequence(params String?[])
Initializes a new instance of the
CStringSequenceclass from a collection of strings. -
CStringSequence(params CString?[])
Initializes a new instance of the
CStringSequenceclass from a collection of UTF-8 strings. -
CStringSequence(ReadOnlySpan<CString>)
Initializes a new instance of the
CStringSequenceclass from a read-only span of UTF-8 strings. -
CStringSequence(ReadOnlySpan<String>)
Initializes a new instance of the
CStringSequenceclass from a read-only span of strings. -
CStringSequence(IReadOnlySpan<String?>)
Initializes a new instance of the
CStringSequenceclass from a collection of strings. -
CStringSequence(IReadOnlySpan<CString?>)
Initializes a new instance of the
CStringSequenceclass from a collection of UTF-8 strings.
-
ToCString()
Returns a
CStringthat represents the current sequence. -
GetFixedPointer()
Creates an
IFixedPointer.IDisposableinstance 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
CStringsegment within the current buffer.
-
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
CStringSequenceinstance from a UTF-8 buffer. -
Create(ReadOnlySpan<Char>)
Creates a new
CStringSequenceinstance from a UTF-8 buffer represented by a span ofChar. -
GetUnsafe(ReadOnlySpan<ReadOnlyValPtr<Byte>>)
Creates a new
CStringSequenceinstance from a UTF-8 null-terminated text pointer span. -
Parse(String?)
Converts the buffer of a UTF-8 sequence to a
CStringSequenceinstance.
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
Tvalue from the given byte array.Note: ´T´ is ´unmanaged´.
-
ToValue<T>(this Span<Byte>)
Retrieves a
Tvalue from the given byte span.Note: ´T´ is ´unmanaged´.
-
ToValue<T>(this ReadOnlySpan<Byte>)
Retrieves a
Tvalue from the given read-only byte span.Note: ´T´ is ´unmanaged´.
-
AsValue<T>(this ReadOnlySpan<Byte>)
Retrieves a read-only reference to a
Tvalue from the given read-only byte span.Note: ´T´ is ´unmanaged´.
-
AsValue<T>(this Span<Byte>)
Retrieves a reference to a
Tvalue 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 aTDelegatedelegate instance. -
GetUnsafeIntPtr<TDelegate>(this TDelegate)
Retrieves an
IntPtrfrom a memory reference to aTDelegatedelegate instance. -
GetUnsafeUIntPtr<TDelegate>(this TDelegate)
Retrieves a
UIntPtrfrom a memory reference to aTDelegatedelegate 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
TResultvalue. -
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
TResultvalue, passing an additional argument to the function. -
GetFixedMethod<TDelegate>(this TDelegate?)
Creates an
IFixedMethod<TDelegate>.IDisposableinstance by marshalling the currentTDelegateinstance, ensuring a safe interop context.
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 fromSpan<T>instance. -
GetUnsafeValPtr<T>(this ReadOnlySpan<T>)
Retrieves an unsafe
ValPtr<T>pointer fromReadOnlySpan<T>instance. -
GetUnsafePtr<T>(this Span<T>)
Retrieves an unsafe
IntPtrpointer fromSpan<T>instance. -
GetUnsafePtr<T>(this ReadOnlySpan<T>)
Retrieves an unsafe
IntPtrpointer fromReadOnlySpan<T>instance. -
GetUnsafeUIntPtr<T>(this Span<T>)
Retrieves an unsafe
UIntPtrpointer fromSpan<T>instance. -
GetUnsafeUIntPtr<T>(this ReadOnlySpan<T>)
Retrieves an unsafe
UIntPtrpointer fromReadOnlySpan<T>instance. -
AsBytes<TSource>(this Span<TSource>)
Reinterprets the span of
TSourceas a binary span.Note:
TSourceisunmanaged. -
AsBytes<TSource>(this ReadOnlySpan<TSource>)
Reinterprets the read-only span of
TSourceas a read-only binary span.Note:
TSourceisunmanaged. -
AsValues<TSource, TDestination>(this Span<TSource>)
Reinterprets the span of
TSourceas a span ofTDestination.Note:
TSourceisunmanaged.TDestinationisunmanaged. -
AsValues<TSource, TDestination>(this ReadOnlySpan<TSource>)
Reinterprets the read-only span of
TSourceas a read-only span ofTDestination.Note:
TSourceisunmanaged.TDestinationisunmanaged. -
AsValues<TSource, TDestination>(this Span<TSource>, Span<Byte>)
Reinterprets the span of
TSourceas a span ofTDestination.Note:
TSourceisunmanaged.TDestinationisunmanaged. -
AsValues<TSource, TDestination>(this Span<TSource>, ReadOnlySpan<Byte>)
Reinterprets the span of
TSourceas a read-only span ofTDestination.Note:
TSourceisunmanaged.TDestinationisunmanaged. -
AsValues<TSource, TDestination>(this ReadOnlySpan<TSource>, ReadOnlySpan<Byte>)
Reinterprets the read-only span of
TSourceas a read-only span ofTDestination.Note:
TSourceisunmanaged.TDestinationisunmanaged. -
GetFixedContext<T>(this ReadOnlyMemory<T>)
Creates an
IReadOnlyFixedContext<T>.IDisposableinstance by pinning the currentReadOnlyMemory<T>instance, ensuring a safe context for accessing the fixed memory.Note:
Tisunmanaged. -
GetFixedContext<T>(this Memory<T>)
Creates an
IFixedContext<T>.IDisposableinstance by pinning the currentMemory<T>instance, ensuring a safe context for accessing the fixed memory.Note:
Tisunmanaged. -
GetFixedMemory<T>(this ReadOnlyMemory<T>)
Creates an
IReadOnlyFixedMemory<T>.IDisposableinstance by pinning the currentReadOnlyMemory<T>instance, ensuring a safe context for accessing the fixed memory.Note:
Tisunmanaged. -
GetFixedMemory<T>(this Memory<T>)
Creates an
IFixedMemory<T>.IDisposableinstance by pinning the currentMemory<T>instance, ensuring a safe context for accessing the fixed memory.Note:
Tisunmanaged. -
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
IntPtrinstance is zero. -
IsZero(this UIntPtr)
Determines if the
UIntPtrinstance is zero. -
ToUIntPtr(this IntPtr)
Converts the specified
IntPtrinstance to aUIntPtrinstance. -
ToUIntPtr(this MemoryHandle)
Converts the specified `MemoryHandle` instance to a `UIntPtr` instance. -
ToIntPtr(this UIntPtr)
Converts the specified
UIntPtrinstance to aIntPtrinstance. -
ToIntPtr(this MemoryHandle)
Converts the specified
MemoryHandleinstance to aIntPtrinstance. -
GetUnsafeString(this IntPtr)
Generates a
Stringinstance from the memory at the givenIntPtr, interpreting the contents as UTF-16 text. -
GetUnsafeString(this UIntPtr)
Generates a
Stringinstance from the memory at the givenUIntPtr, interpreting the contents as UTF-16 text. -
GetUnsafeString(this MemoryHandle)
Generates a
Stringinstance from the memory at the givenMemoryHandle, interpreting the contents as UTF-16 text. -
GetUnsafeString(this IntPtr, Int32)
Generates a
Stringinstance from the memory at the givenIntPtr, interpreting the contents as UTF-16 text. -
GetUnsafeString(this UIntPtr, Int32)
Generates a
Stringinstance from the memory at the givenUIntPtr, interpreting the contents as UTF-16 text. -
GetUnsafeString(this MemoryHandle, Int32)
Generates a
Stringinstance from the memory at the givenMemoryHandle, interpreting the contents as UTF-16 text. -
GetUnsafeArray<T>(this IntPtr, Int32)
Generates a
Tarray by copying values from memory starting at the location referenced by anIntPtr.Note: ´T´ is ´unmanaged´.
-
GetUnsafeArray<T>(this UIntPtr, Int32)
Generates a
Tarray by copying values from memory starting at the location referenced by aUIntPtr.Note: ´T´ is ´unmanaged´.
-
GetUnsafeArray<T>(this MemoryHandle, Int32)
Generates a
Tarray by copying values from memory starting at the location referenced by aMemoryHandle.Note: ´T´ is ´unmanaged´.
-
GetUnsafeSpan<T>(this IntPtr, Int32)
Generates a
Span<T>instance from anIntPtr, interpreting the memory at the specified location as a sequence ofunmanagedvalues.Note: ´T´ is ´unmanaged´.
-
GetUnsafeSpan<T>(this UIntPtr, Int32)
Generates a
Span<T>instance from aUIntPtr, interpreting the memory at the specified location as a sequence ofunmanagedvalues.Note: ´T´ is ´unmanaged´.
-
GetUnsafeSpan<T>(this MemoryHandle, Int32)
Generates a
Span<T>instance from aMemoryHandle, interpreting the memory at the specified location as a sequence ofunmanagedvalues.Note: ´T´ is ´unmanaged´.
-
GetUnsafeReadOnlySpan<T>(this IntPtr, Int32)
Generates a
ReadOnlySpan<T>instance from anIntPtr, interpreting the memory at the specified location as a sequence ofunmanagedvalues.Note: ´T´ is ´unmanaged´.
-
GetUnsafeReadOnlySpan<T>(this UIntPtr, Int32)
Generates a
ReadOnlySpan<T>instance from aUIntPtr, interpreting the memory at the specified location as a sequence ofunmanagedvalues.Note: ´T´ is ´unmanaged´.
-
GetUnsafeReadOnlySpan<T>(this MemoryHandle, Int32)
Generates a
ReadOnlySpan<T>instance from aMemoryHandle, interpreting the memory at the specified location as a sequence ofunmanagedvalues.Note: ´T´ is ´unmanaged´.
-
GetUnsafeDelegate<TDelegate>(this IntPtr)
Generates a delegate of type
TDelegatefrom anIntPtr. -
GetUnsafeDelegate<TDelegate>(this UIntPtr)
Creates a delegate of type
TDelegatefrom aUIntPtr. -
GetUnsafeReference<T>(this IntPtr)
Generates a memory reference to an
unmanagedvalue of typeTfromIntPtr. -
GetUnsafeReference<T>(this UIntPtr)
Generates a memory reference to an
unmanagedvalue of typeTfromUIntPtr. -
GetUnsafeReadOnlyReference<T>(this IntPtr)
Generates a read-only memory reference to an
unmanagedvalue of typeTfromIntPtr. -
GetUnsafeReadOnlyReference<T>(this UIntPtr)
Generates a read-only memory reference to an
unmanagedvalue of typeTfromUIntPtr. -
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>.
PointerCStringExtensions
Set of extensions for CString operations with IntPtr and UIntPtr instances.
-
GetUnsafeCString(this IntPtr, Int32)
Generates a
CStringinstance using the memory reference pointed to by the givenIntPtr, considering it as the start of a UTF-8 encoded string. -
GetUnsafeCString(this UIntPtr, Int32)
Generates a
CStringinstance using the memory reference pointed to by the givenUIntPtr, considering it as the start of a UTF-8 encoded string. -
GetUnsafeCString(this MemoryHandle, Int32)
Generates a
CStringinstance using the memory reference pointed to by the givenMemoryHandle, 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.Utf8Viewfrom the givenCStringSequenceinstance, 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 aNullReferenceException.
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 anunmanagedvalue of typeT. -
GetUnsafeIntPtr<T>(ref this T)
Obtains an unsafe pointer of type
IntPtrfrom a reference to anunmanagedvalue of typeT. -
GetUnsafeUIntPtr<T>(ref this T)
Obtains an unsafe pointer of type
UIntPtrfrom a reference to anunmanagedvalue of typeT. -
Transform<TSource, TDestination>(ref this TSource)
Generates a reference for an
unmanagedvalue of typeTDestinationfrom an existing reference to anunmanagedvalue of typeTSource. -
AsBytes<TSource>(ref this TSource)
Creates a
Span<Byte>from a reference to anunmanagedvalue of typeTSource. -
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
Telements 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
Telements from given array pool, ensuring a safe context for accessing the fixed memory. -
ToBytes<T>(this T)
Converts a given
unmanagedvalue of typeTinto an array ofByte. -
ToBytes<TSource>(this TSource[]?)
Converts an array of
unmanagedvalues of typeTSourceinto an array ofByte. -
ToValues<TSource, TDestination>(this TSource[]?)
Converts an array of
unmanagedvalues of typeTSourceinto an array of anotherunmanagedvalue typeTDestination. -
ToValues<TSource, TDestination>(this TSource[]?, out Byte[]?)
Converts an array of
unmanagedvalues of typeTSourceinto an array of anotherunmanagedvalue typeTDestinationand 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.
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.
-
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.Note: Starting with .NET 6.0, this property enables trimming by allowing the linker to remove unreachable code on desktop platforms.
SystemInfo
Provides information about the runtime system.
-
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.
-
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.
-
BufferAutoCompositionEnabled
Indicates whether metadata for any required buffer is auto-composed.Note: This property will always be false if compiled with
IlcDisableReflection=trueor if thePInvoke.DisableBufferAutoCompositionfeature switch is enabled.
-
Alloc<T>(UInt16, ScopedBufferAction<T>, Boolean)
Allocates a buffer with
countelements and executesaction. -
Alloc<T, TState>(UInt16, TState, ScopedBufferAction<T, TState>, Boolean)
Allocates a buffer with
countelements and executesaction. -
Alloc<T, TResult>(UInt16, ScopedBufferFunc<T, TResult>, Boolean)
Allocates a buffer with
countelements and executesfunc. -
Alloc<T, TState, TResult>(UInt16, TState, ScopedBufferFunc<T, TState, TResult>, Boolean)
Allocates a buffer with
countelements and executesfunc. -
Register<TBuffer>()
Registers object buffer.Note:
TBufferisstructandIManagedBuffer<Object>. In .NET 6.0 and earlier, this method uses reflection. -
Register<T, TBuffer>()
Registers
Tbuffer.Note:
Tisstruct.TBufferisstructandIManagedBuffer<T>. In .NET 6.0 and earlier, this method uses reflection. -
RegisterNullable<T, TBuffer>()
Registers
T?buffer.Note:
Tisstruct.TBufferisstructandIManagedBuffer<T?>. In .NET 6.0 and earlier, this method uses reflection. -
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
Titems.Note:
Tisstruct. 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:
Tisstruct. 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.
-
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
Iso639P1enum value corresponding to the current user interface culture.
-
SizeOf<T>()
Gets the memory size of
Tstructure.Note:
Tisunmanaged. -
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
TDelegatedelegate 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
TDelegateof an exported symbol.Note: This method is available only on .NET Core 3.0 and later.
-
GetIso639P1(CultureInfo)
Retrieves the
Iso639P1enum value corresponding to the specified culture. -
GetUnsafeFuncPtr<TDelegate>(TDelegate)
Creates an
FuncPtr<TDelegate>from a memory reference to aTDelegatedelegate instance. -
GetUnsafeValPtr<T>(in T)
Retrieves an unsafe
ReadOnlyValPtr<T>pointer from a read-only reference to aTvalue.Note: Starting with .NET 9.0,
Tcan be aref 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,
Tcan be aref struct. -
GetUnsafeIntPtr<T>(in T)
Retrieves an unsafe
IntPtrpointer from a read-only reference to aTunmanagedvalue. -
GetUnsafeUIntPtr<T>(in T)
Retrieves an unsafe
UIntPtrpointer from a read-only reference to aTunmanagedvalue. -
Transform<TSource, TDestination>(in TSource)
Transforms a read-only reference of an
unmanagedvalue of typeTSourceinto a read-only reference of anunmanagedvalue of typeTDestination. -
TransformReference<TSource, TDestination>(ref TSource)
Transforms a reference of an
unmanagedvalue of typeTSourceinto a reference of anunmanagedvalue of typeTDestination. -
ToBytes<T>(in TSource)
Retrieves a
Bytearray from a read-only reference to aTSourcevalue.Note:
TSourceisunmanaged. -
AsBytes<TSource>(in TSource)
Creates a
ReadOnlySpan<Byte>from an exising read-only reference to aTSourceunmanagedvalue. -
AsBinarySpan<TSource>(ref TSource)
Creates a
Span<Byte>from an exising reference to aTSourcevalue.Note:
TSourceisunmanaged. -
CreateArray<T, TState>(Int32, TState, SpanAction<T, TState>)
Creates a new
Tarray with a specific length and initializes it after creation by using the specified callback.Note:
Tisunmanaged. -
CopyBytes<T>(in TSource, Span<Byte>, Int32)
Performs a binary copy of the given
TSourceto the destination span.Note:
TSourceisunmanaged. -
GetEnumValuesSpan<TEnum>()
Creates a new span over an array of the values of the constants in a specified enumeration type.
Note:
TEnumisSystem.Enum. -
GetEnumNamesSpan<TEnum>()
Creates a new span over an array of the names of the constants in a specified enumeration type.
Note:
TEnumisSystem.Enum. -
GetValuesFixedContext<TEnum>()
Creates a new
IReadOnlyFixedContext<TEnum>.IDisposableinstance by pinning an array of the values of the constants in a specified enumeration type.Note:
TEnumisSystem.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,
Tcan be aref 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
TandTArgcan beref structtypes. -
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,
Tcan be aref 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
TandTArgcan beref structtypes. -
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,
Tcan be aref 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,
Tcan be aref 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
TandTArgcan beref structtypes. -
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
TandTArgcan beref structtypes. -
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,
Tcan be aref 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,
Tcan be aref 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
TandTArgcan beref structtypes. -
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
TandTArgcan beref structtypes. -
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,
TArgcan be aref 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,
TArgcan be aref 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,
TArgcan be aref 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,
TArgcan be aref 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,
TArgcan be aref 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,
TArgcan be aref 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,
TArgcan be aref 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,
TArgcan be aref struct. -
GetFixedMethod<TDelegate>(TDelegate?)
Creates an
IFixedMethod<TDelegate>.IDisposableinstance by marshalling the currentTDelegateinstance, ensuring a safe interop context.
This project is licensed under the MIT License, one of the most permissive and widely-used open-source licenses.
- 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.
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.
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. Below are some ways you can get involved:
If you encounter a bug, experience unexpected behavior, or have suggestions for improvement, feel free to open an issue. Please include as much detail as possible, such as:
- Steps to reproduce the problem
- Your environment (e.g., OS, software version)
- Any relevant logs or screenshots
Have an idea for a new feature or enhancement? Open an issue with a clear description of your proposal and why you think it would benefit the project.
You can directly contribute to the project by:
- Fixing bugs
- Adding new features
- Improving existing functionality
- Enhancing documentation
To contribute code:
- Fork the repository.
- Create a new branch for your changes.
- Make your changes and commit them with clear and concise messages.
- Submit a pull request for review.
Feel free to discuss your ideas or changes in an issue or pull request to align with the project's goals.
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
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. 🚀