218 lines
7.8 KiB
C#
218 lines
7.8 KiB
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace System.Reflection.Emit
|
|
{
|
|
/// <summary>Represents the class that describes how to marshal a field from managed to unmanaged code. This class cannot be inherited.</summary>
|
|
// Token: 0x0200021D RID: 541
|
|
[ComVisible(true)]
|
|
[Obsolete("An alternate API is available: Emit the MarshalAs custom attribute instead.")]
|
|
[Serializable]
|
|
public sealed class UnmanagedMarshal
|
|
{
|
|
// Token: 0x06001CE3 RID: 7395 RVA: 0x0006D294 File Offset: 0x0006B494
|
|
private UnmanagedMarshal(UnmanagedType maint, int cnt)
|
|
{
|
|
this.count = cnt;
|
|
this.t = maint;
|
|
this.tbase = maint;
|
|
}
|
|
|
|
// Token: 0x06001CE4 RID: 7396 RVA: 0x0006D2B4 File Offset: 0x0006B4B4
|
|
private UnmanagedMarshal(UnmanagedType maint, UnmanagedType elemt)
|
|
{
|
|
this.count = 0;
|
|
this.t = maint;
|
|
this.tbase = elemt;
|
|
}
|
|
|
|
/// <summary>Gets an unmanaged base type. This property is read-only.</summary>
|
|
/// <returns>An UnmanagedType object.</returns>
|
|
/// <exception cref="T:System.ArgumentException">The unmanaged type is not an LPArray or a SafeArray. </exception>
|
|
// Token: 0x1700052E RID: 1326
|
|
// (get) Token: 0x06001CE5 RID: 7397 RVA: 0x0006D2D4 File Offset: 0x0006B4D4
|
|
public UnmanagedType BaseType
|
|
{
|
|
get
|
|
{
|
|
if (this.t == UnmanagedType.LPArray || this.t == UnmanagedType.SafeArray)
|
|
{
|
|
throw new ArgumentException();
|
|
}
|
|
return this.tbase;
|
|
}
|
|
}
|
|
|
|
/// <summary>Gets a number element. This property is read-only.</summary>
|
|
/// <returns>An integer indicating the element count.</returns>
|
|
/// <exception cref="T:System.ArgumentException">The argument is not an unmanaged element count. </exception>
|
|
// Token: 0x1700052F RID: 1327
|
|
// (get) Token: 0x06001CE6 RID: 7398 RVA: 0x0006D308 File Offset: 0x0006B508
|
|
public int ElementCount
|
|
{
|
|
get
|
|
{
|
|
return this.count;
|
|
}
|
|
}
|
|
|
|
/// <summary>Indicates an unmanaged type. This property is read-only.</summary>
|
|
/// <returns>An <see cref="T:System.Runtime.InteropServices.UnmanagedType" /> object.</returns>
|
|
// Token: 0x17000530 RID: 1328
|
|
// (get) Token: 0x06001CE7 RID: 7399 RVA: 0x0006D310 File Offset: 0x0006B510
|
|
public UnmanagedType GetUnmanagedType
|
|
{
|
|
get
|
|
{
|
|
return this.t;
|
|
}
|
|
}
|
|
|
|
/// <summary>Gets a GUID. This property is read-only.</summary>
|
|
/// <returns>A <see cref="T:System.Guid" /> object.</returns>
|
|
/// <exception cref="T:System.ArgumentException">The argument is not a custom marshaler. </exception>
|
|
// Token: 0x17000531 RID: 1329
|
|
// (get) Token: 0x06001CE8 RID: 7400 RVA: 0x0006D318 File Offset: 0x0006B518
|
|
public Guid IIDGuid
|
|
{
|
|
get
|
|
{
|
|
return new Guid(this.guid);
|
|
}
|
|
}
|
|
|
|
/// <summary>Specifies a fixed-length array (ByValArray) to marshal to unmanaged code.</summary>
|
|
/// <returns>An <see cref="T:System.Reflection.Emit.UnmanagedMarshal" /> object.</returns>
|
|
/// <param name="elemCount">The number of elements in the fixed-length array. </param>
|
|
/// <exception cref="T:System.ArgumentException">The argument is not a simple native type. </exception>
|
|
// Token: 0x06001CE9 RID: 7401 RVA: 0x0006D328 File Offset: 0x0006B528
|
|
public static UnmanagedMarshal DefineByValArray(int elemCount)
|
|
{
|
|
return new UnmanagedMarshal(UnmanagedType.ByValArray, elemCount);
|
|
}
|
|
|
|
/// <summary>Specifies a string in a fixed array buffer (ByValTStr) to marshal to unmanaged code.</summary>
|
|
/// <returns>An <see cref="T:System.Reflection.Emit.UnmanagedMarshal" /> object.</returns>
|
|
/// <param name="elemCount">The number of elements in the fixed array buffer. </param>
|
|
/// <exception cref="T:System.ArgumentException">The argument is not a simple native type. </exception>
|
|
// Token: 0x06001CEA RID: 7402 RVA: 0x0006D334 File Offset: 0x0006B534
|
|
public static UnmanagedMarshal DefineByValTStr(int elemCount)
|
|
{
|
|
return new UnmanagedMarshal(UnmanagedType.ByValTStr, elemCount);
|
|
}
|
|
|
|
/// <summary>Specifies an LPArray to marshal to unmanaged code. The length of an LPArray is determined at runtime by the size of the actual marshaled array.</summary>
|
|
/// <returns>An <see cref="T:System.Reflection.Emit.UnmanagedMarshal" /> object.</returns>
|
|
/// <param name="elemType">The unmanaged type to which to marshal the array. </param>
|
|
/// <exception cref="T:System.ArgumentException">The argument is not a simple native type. </exception>
|
|
// Token: 0x06001CEB RID: 7403 RVA: 0x0006D340 File Offset: 0x0006B540
|
|
public static UnmanagedMarshal DefineLPArray(UnmanagedType elemType)
|
|
{
|
|
return new UnmanagedMarshal(UnmanagedType.LPArray, elemType);
|
|
}
|
|
|
|
/// <summary>Specifies a SafeArray to marshal to unmanaged code.</summary>
|
|
/// <returns>An <see cref="T:System.Reflection.Emit.UnmanagedMarshal" /> object.</returns>
|
|
/// <param name="elemType">The base type or the UnmanagedType of each element of the array. </param>
|
|
/// <exception cref="T:System.ArgumentException">The argument is not a simple native type. </exception>
|
|
// Token: 0x06001CEC RID: 7404 RVA: 0x0006D34C File Offset: 0x0006B54C
|
|
public static UnmanagedMarshal DefineSafeArray(UnmanagedType elemType)
|
|
{
|
|
return new UnmanagedMarshal(UnmanagedType.SafeArray, elemType);
|
|
}
|
|
|
|
/// <summary>Specifies a given type that is to be marshaled to unmanaged code.</summary>
|
|
/// <returns>An <see cref="T:System.Reflection.Emit.UnmanagedMarshal" /> object.</returns>
|
|
/// <param name="unmanagedType">The unmanaged type to which the type is to be marshaled. </param>
|
|
/// <exception cref="T:System.ArgumentException">The argument is not a simple native type. </exception>
|
|
// Token: 0x06001CED RID: 7405 RVA: 0x0006D358 File Offset: 0x0006B558
|
|
public static UnmanagedMarshal DefineUnmanagedMarshal(UnmanagedType unmanagedType)
|
|
{
|
|
return new UnmanagedMarshal(unmanagedType, unmanagedType);
|
|
}
|
|
|
|
// Token: 0x06001CEE RID: 7406 RVA: 0x0006D364 File Offset: 0x0006B564
|
|
public static UnmanagedMarshal DefineCustom(Type typeref, string cookie, string mtype, Guid id)
|
|
{
|
|
UnmanagedMarshal unmanagedMarshal = new UnmanagedMarshal(UnmanagedType.CustomMarshaler, UnmanagedType.CustomMarshaler);
|
|
unmanagedMarshal.mcookie = cookie;
|
|
unmanagedMarshal.marshaltype = mtype;
|
|
unmanagedMarshal.marshaltyperef = typeref;
|
|
if (id == Guid.Empty)
|
|
{
|
|
unmanagedMarshal.guid = string.Empty;
|
|
}
|
|
else
|
|
{
|
|
unmanagedMarshal.guid = id.ToString();
|
|
}
|
|
return unmanagedMarshal;
|
|
}
|
|
|
|
// Token: 0x06001CEF RID: 7407 RVA: 0x0006D3C0 File Offset: 0x0006B5C0
|
|
internal static UnmanagedMarshal DefineLPArrayInternal(UnmanagedType elemType, int sizeConst, int sizeParamIndex)
|
|
{
|
|
return new UnmanagedMarshal(UnmanagedType.LPArray, elemType)
|
|
{
|
|
count = sizeConst,
|
|
param_num = sizeParamIndex,
|
|
has_size = true
|
|
};
|
|
}
|
|
|
|
// Token: 0x06001CF0 RID: 7408 RVA: 0x0006D3EC File Offset: 0x0006B5EC
|
|
internal MarshalAsAttribute ToMarshalAsAttribute()
|
|
{
|
|
MarshalAsAttribute marshalAsAttribute = new MarshalAsAttribute(this.t);
|
|
marshalAsAttribute.ArraySubType = this.tbase;
|
|
marshalAsAttribute.MarshalCookie = this.mcookie;
|
|
marshalAsAttribute.MarshalType = this.marshaltype;
|
|
marshalAsAttribute.MarshalTypeRef = this.marshaltyperef;
|
|
if (this.count == -1)
|
|
{
|
|
marshalAsAttribute.SizeConst = 0;
|
|
}
|
|
else
|
|
{
|
|
marshalAsAttribute.SizeConst = this.count;
|
|
}
|
|
if (this.param_num == -1)
|
|
{
|
|
marshalAsAttribute.SizeParamIndex = 0;
|
|
}
|
|
else
|
|
{
|
|
marshalAsAttribute.SizeParamIndex = (short)this.param_num;
|
|
}
|
|
return marshalAsAttribute;
|
|
}
|
|
|
|
// Token: 0x040009CA RID: 2506
|
|
private int count;
|
|
|
|
// Token: 0x040009CB RID: 2507
|
|
private UnmanagedType t;
|
|
|
|
// Token: 0x040009CC RID: 2508
|
|
private UnmanagedType tbase;
|
|
|
|
// Token: 0x040009CD RID: 2509
|
|
private string guid;
|
|
|
|
// Token: 0x040009CE RID: 2510
|
|
private string mcookie;
|
|
|
|
// Token: 0x040009CF RID: 2511
|
|
private string marshaltype;
|
|
|
|
// Token: 0x040009D0 RID: 2512
|
|
private Type marshaltyperef;
|
|
|
|
// Token: 0x040009D1 RID: 2513
|
|
private int param_num;
|
|
|
|
// Token: 0x040009D2 RID: 2514
|
|
private bool has_size;
|
|
}
|
|
}
|