Table of Contents

Class SafeArrayMarshaller

Namespace
CsCom.Runtime
Assembly
CsCom.Runtime.dll

Marshals arrays of up to three dimensions as SAFEARRAYs.

[CustomMarshaller(typeof(Array), MarshalMode.Default, typeof(SafeArrayMarshaller))]
public static class SafeArrayMarshaller
Inheritance
SafeArrayMarshaller
Inherited Members

Remarks

The variant type of the elements is derived from the element type of the array, as by SafeArrayMarshaller<T>, so the arrays passed to COM methods must have the element type of the SAFEARRAY, e.g. string[,] for SAFEARRAY(BSTR). Returned arrays are converted to zero-based arrays whose element type is determined by the variant type of the SAFEARRAY; the elements of multidimensional arrays keep their indices.

Methods

ConvertToManaged(nint)

Converts a SAFEARRAY to an array.

public static Array? ConvertToManaged(nint unmanaged)

Parameters

unmanaged nint

Returns

Array

ConvertToManaged2D<T>(nint)

Converts a two-dimensional SAFEARRAY to a zero-based array of T, converting the elements when the variant type of the SAFEARRAY does not match. Used by the marshallers generated for the parameters whose rank is known.

public static T[,]? ConvertToManaged2D<T>(nint unmanaged)

Parameters

unmanaged nint

Returns

T[,]

Type Parameters

T

Exceptions

SafeArrayRankMismatchException

The SAFEARRAY does not have two dimensions.

ConvertToManaged3D<T>(nint)

Converts a three-dimensional SAFEARRAY to a zero-based array of T, converting the elements when the variant type of the SAFEARRAY does not match. Used by the marshallers generated for the parameters whose rank is known.

public static T[,,]? ConvertToManaged3D<T>(nint unmanaged)

Parameters

unmanaged nint

Returns

T[,,]

Type Parameters

T

Exceptions

SafeArrayRankMismatchException

The SAFEARRAY does not have three dimensions.

ConvertToUnmanaged(Array?)

Creates a SAFEARRAY from an array.

public static nint ConvertToUnmanaged(Array? managed)

Parameters

managed Array

Returns

nint

Free(nint)

Destroys the SAFEARRAY.

public static void Free(nint unmanaged)

Parameters

unmanaged nint