RuntimeInfrastructure mscorlib [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ] 1.0.5000.0 2.0.0.0 4.0.0.0 All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe. System.Attribute System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.ReturnValue | System.AttributeTargets.All, Inherited=false) System.Runtime.InteropServices.ComVisible(true)

You can apply this attribute to parameters, fields, or return values.

This attribute is optional, as each data type has a default marshaling behavior. This attribute is only necessary when a given type can be marshaled to multiple types. For example, you can marshal a string to unmanaged code as either a , a , a , or a . By default, the common language runtime marshals a string parameter as a to COM methods. You can apply the attribute to an individual field or parameter to cause that particular string to be marshaled as a instead of a . The [<topic://cpgrfTypeLibraryExporterTlbexpexe>] passes your marshaling preferences to the common language runtime.

Some parameters and return values have different default marshaling behavior when used with COM interop or platform invoke. By default, the runtime marshals a string parameter (and fields in a value type) as a to a platform invoke method or function. For additional information, see [<topic://cpcondefaultmarshalingbehavior>].

In most cases, the attribute simply identifies the format of the unmanaged data using the enumeration, as shown in the following C# signature:

`void MyMethod([MarshalAs(LPStr)] String s);`

Some enumeration members require additional information. For example, additional information is needed when the is . For a complete description of how to use this attribute with arrays, see [<topic://cpcondefaultmarshalingforarrays>].

The [<topic://cpgrfTypeLibraryImporterTlbimpexe>] also applies this attribute to parameters, fields, and return values to indicate that the data type in the input type library is not the default type for the corresponding managed data type. Tlbimp.exe always applies the to and types for clarity, regardless of the type specified in the input type library.

The does not support marshaling of generic types.

Indicates how to marshal the data between managed and unmanaged code.

- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  This constructor takes an underlying 16-bit signed integer that represents each enumeration member. The [<topic://cpgrfTypeLibraryImporterTlbimpexe>] uses this constructor.

  Initializes a new instance of the class with the specified value.

  The value the data is to be marshaled as.
  0
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  For readable code that is less prone to error, always use this constructor.

  Initializes a new instance of the class with the specified enumeration member.

  The value the data is to be marshaled as.
  0
- Field
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Runtime.InteropServices.UnmanagedType

  You can set this parameter to a value from the enumeration to specify the type of the array's elements. If a type is not specified, the default unmanaged type corresponding to the managed array's element type is used. For example, the ArraySubType for a LPWStr array in COM is . For additional information, see [<topic://cpcondefaultmarshalingforarrays>].

  Specifies the element type of the unmanaged or .

  0
- Field
  2.0.0.0
  4.0.0.0
  System.Int32 To be added.

  Specifies the parameter index of the unmanaged iid_is attribute used by COM.

- Field
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.String

  This field is optional when using a custom marshaler.

  You can set this field to a string that supplies additional information to a custom marshaler. For example, the same marshaler can be used to provide a number of wrappers, where the cookie is used to indicate the specific wrapper.

  Provides additional information to a custom marshaler.

  0
- Field
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Runtime.InteropServices.ComVisible(true)
  System.String

  You can use either the or field specify a custom marshaler type for the attributed parameter, field, or return type. The field enables you to specify a string representing the fully qualified name of a custom marshaler. It is useful for late-bound references, but is less preferred than for specifying a custom marshaler. For additional information about creating and using custom marshalers, see Custom Marshaling.

  Specifies the fully qualified name of a custom marshaler.

  0
- Field
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Runtime.InteropServices.ComVisible(true)
  System.Type

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

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

  You can set a 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.

  Implements as a type.

  0
- Field
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Runtime.InteropServices.VarEnum

  You can set this field to a value from the enumeration to specify the type of the safe array's elements. If a type is not specified, the managed element type's default type (if passed as a VARIANT) is used. For example, the SafeArraySubType for an int array in COM is . For additional information, see [<topic://cpcondefaultmarshalingforarrays>].

  Indicates the element type of the .

- Field
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Type

  Initialize this field with your custom type to enable the elements of the SAFEARRAY to be marshaled successfully. This field is only needed when the is either , , or . For additional information, see [<topic://cpcondefaultmarshalingforarrays>].

  Indicates the user-defined element type of the .

- Field
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int32

  This field is required for the and members of the enumeration. Because the compressed format of the metadata is limited to 0x1FFFFFFF, the range of allowed values for are (>= 0 and <= 0x1FFFFFFF).

  For additional information, see [<topic://cpcondefaultmarshalingforarrays>].

  Indicates the number of elements in the fixed-length array or the number of characters (not bytes) in a string to import.

  0
- Field
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Int16

  The field supports managed-to-unmanaged and unmanaged-to-managed calls. It does not have any effect on managed code that calls COM objects.

  Depending on the managed type and the attributes applied to it, the array can be passed as a safe array or C-style array.

  When arrays are passed as C-style arrays, the marshaler cannot determine the size of the array. Therefore, to pass an managed array to an unmanaged function or method, you must provide two arguments:

  The array, defined by reference or value.

  The array size, defined by reference or value.

  The zero-based index of the array size parameter is defined by using the field.

  If you specify both and with a field, the sum of the fields' values produces a size total.

  For more information, see [<topic://cpcondefaultmarshalingforarrays>].

  Indicates the zero-based parameter that contains the count of array elements, similar to size_is in COM.

  0
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Runtime.InteropServices.UnmanagedType

  The value indicating how the data is to be marshaled.

  This value is used with to indicate how types should be marshaled between managed and unmanaged code. In some cases, you can use this field with certain UnmanagedType enumeration members. For and , you must use additional named parameters.

  Gets the value the data is to be marshaled as.

  0
0