public sealed class MarshalAsAttribute : Attribute
Object
Attribute
MarshalAsAttribute
mscorlib
RuntimeInfrastructure
Specifies how data is to be marshaled between managed and unmanaged code.
This attribute can be applied to parameters, fields, or return values.Each data type has a default marshaling behavior that is used if this attribute is not present. This attribute is only required when a type can be marshaled as more than one possible types. [Note: The UnmanagedType enumeration specifies possible data types.]
Compilers are required to not preserve this type in metadata as a custom attribute. Instead, compilers are required to emit it directly in the file format, as described in Partition II of the CLI Specification. Metadata consumers, such as the Reflection API, are required to retrieve this data from the file format and return it as if it were a custom attribute.
AttributeUsageAttribute(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.ReturnValue, AllowMultiple=false, Inherited=false)
System.Runtime.InteropServices Namespace
MarshalAsAttribute Constructors
MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType) Constructor
MarshalAsAttribute(short) Constructor
MarshalAsAttribute Fields
MarshalAsAttribute.ArraySubType Field
MarshalAsAttribute.MarshalCookie Field
MarshalAsAttribute.MarshalType Field
MarshalAsAttribute.MarshalTypeRef Field
MarshalAsAttribute.SizeConst Field
MarshalAsAttribute.SizeParamIndex Field
MarshalAsAttribute Properties
public MarshalAsAttribute(UnmanagedType unmanagedType);
Constructs and initializes a new instance of the MarshalAsAttribute class with the specified UnmanagedType value.
- unmanagedType
- A UnmanagedType value indicating how the data is to be marshaled.
System.Runtime.InteropServices.MarshalAsAttribute Class, System.Runtime.InteropServices Namespace
public MarshalAsAttribute(short unmanagedType);
Constructs and initializes a new instance of the MarshalAsAttribute class with the specified value.
- unmanagedType
- A Int16 containing a UnmanagedType value indicating how the data is to be marshaled.
System.Runtime.InteropServices.MarshalAsAttribute Class, System.Runtime.InteropServices Namespace
public UnmanagedType ArraySubType;
A UnmanagedType enumeration value that specifies the type of elements in an array.
System.Runtime.InteropServices.MarshalAsAttribute Class, System.Runtime.InteropServices Namespace
public string MarshalCookie;
A String that is used with System.Runtime.InteropServices.UnmanagedType.CustomMarshaler to hold a cookie that is passed to the custom marshaler. The value of the cookie is defined by the custom marshaler implementation.
This field is used only with System.Runtime.InteropServices.UnmanagedType.CustomMarshaler and is optional.
System.Runtime.InteropServices.MarshalAsAttribute Class, System.Runtime.InteropServices Namespace
public string MarshalType;
A String that identifies the Type of a custom marshaler.
This field is used only with System.Runtime.InteropServices.UnmanagedType.CustomMarshaler and is required.A custom marshaler is a type that is capable of marshaling calls from a specific managed type to a specific unmanaged type and vice versa.
System.Runtime.InteropServices.MarshalAsAttribute Class, System.Runtime.InteropServices Namespace
public Type MarshalTypeRef;
Specifies the managed Type of the argument being marshaled.
This field is used only with System.Runtime.InteropServices.UnmanagedType.CustomMarshaler and is required.
System.Runtime.InteropServices.MarshalAsAttribute Class, System.Runtime.InteropServices Namespace
public int SizeConst;
A Int32 that specifies the size, in bytes, of the constant size array being marshaled.
This field is used only with the System.Runtime.InteropServices.UnmanagedType.ByValArray or System.Runtime.InteropServices.UnmanagedType.LPArray enumeration value. When using either of these unmanaged types, either this field or System.Runtime.InteropServices.MarshalAsAttribute.SizeParamIndex is required.
System.Runtime.InteropServices.MarshalAsAttribute Class, System.Runtime.InteropServices Namespace
public short SizeParamIndex;
A Int16 that identifies the position (starting with zero) of the method argument that identifies the size of the array being marshaled.
This field is used only with the System.Runtime.InteropServices.UnmanagedType.ByValArray or System.Runtime.InteropServices.UnmanagedType.LPArray enumeration value. When using either of these unmanaged types, either this field or System.Runtime.InteropServices.MarshalAsAttribute.SizeConst is required.
System.Runtime.InteropServices.MarshalAsAttribute Class, System.Runtime.InteropServices Namespace
public UnmanagedType Value { get; }
Gets the UnmanagedType value the data is to be marshaled as.
The UnmanagedType value indicating how the data is to be marshaled.
This property is read-only.
System.Runtime.InteropServices.MarshalAsAttribute Class, System.Runtime.InteropServices Namespace