MarshalTypeRef Field

MarshalAsAttribute.MarshalTypeRef Field


Implements MarshalAsAttribute.MarshalType as a type.

Namespace:   System.Runtime.InteropServices
Assembly:  mscorlib (in mscorlib.dll)

public Type MarshalTypeRef

Field Value

Type: System.Type

You can use either the MarshalTypeRef or MarshalType field to specify a custom marshaler type for the attributed parameter, field, or return type. The MarshalTypeRef field allows easier usage of MarshalType by shortening the syntax. In the following example, the first line represents syntax using MarshalType and the second line represents syntax using MarshalTypeRef.

[MarshalAs(UnmanagedType.CustomMarshaler, MarshalType = "Assembly, NameSpace.TypeName")] 
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(NameSpace.TypeName)]

You can set a Type object using typeof in C#, GetType in Visual Basic, or typeid in C++. For additional information about creating and using custom marshalers, see Custom Marshaling.

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
© 2015 Microsoft