413 lines
18 KiB
C#
413 lines
18 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace System.Reflection.Emit
|
|
{
|
|
/// <summary>Defines and represents a field. This class cannot be inherited.</summary>
|
|
// Token: 0x020001F3 RID: 499
|
|
[ClassInterface(ClassInterfaceType.None)]
|
|
[ComDefaultInterface(typeof(_FieldBuilder))]
|
|
[ComVisible(true)]
|
|
public sealed class FieldBuilder : FieldInfo, _FieldBuilder
|
|
{
|
|
// Token: 0x06001A16 RID: 6678 RVA: 0x00062920 File Offset: 0x00060B20
|
|
internal FieldBuilder(TypeBuilder tb, string fieldName, Type type, FieldAttributes attributes, Type[] modReq, Type[] modOpt)
|
|
{
|
|
if (type == null)
|
|
{
|
|
throw new ArgumentNullException("type");
|
|
}
|
|
this.attrs = attributes;
|
|
this.name = fieldName;
|
|
this.type = type;
|
|
this.modReq = modReq;
|
|
this.modOpt = modOpt;
|
|
this.offset = -1;
|
|
this.typeb = tb;
|
|
this.table_idx = tb.get_next_table_index(this, 4, true);
|
|
}
|
|
|
|
/// <summary>Maps a set of names to a corresponding set of dispatch identifiers.</summary>
|
|
/// <param name="riid">Reserved for future use. Must be IID_NULL.</param>
|
|
/// <param name="rgszNames">Passed-in array of names to be mapped.</param>
|
|
/// <param name="cNames">Count of the names to be mapped.</param>
|
|
/// <param name="lcid">The locale context in which to interpret the names.</param>
|
|
/// <param name="rgDispId">Caller-allocated array which receives the IDs corresponding to the names.</param>
|
|
/// <exception cref="T:System.NotImplementedException">The method is called late-bound using the COM IDispatch interface.</exception>
|
|
// Token: 0x06001A17 RID: 6679 RVA: 0x00062988 File Offset: 0x00060B88
|
|
void _FieldBuilder.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
/// <summary>Retrieves the type information for an object, which can then be used to get the type information for an interface.</summary>
|
|
/// <param name="iTInfo">The type information to return.</param>
|
|
/// <param name="lcid">The locale identifier for the type information.</param>
|
|
/// <param name="ppTInfo">Receives a pointer to the requested type information object.</param>
|
|
/// <exception cref="T:System.NotImplementedException">The method is called late-bound using the COM IDispatch interface.</exception>
|
|
// Token: 0x06001A18 RID: 6680 RVA: 0x00062990 File Offset: 0x00060B90
|
|
void _FieldBuilder.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
/// <summary>Retrieves the number of type information interfaces that an object provides (either 0 or 1).</summary>
|
|
/// <param name="pcTInfo">Points to a location that receives the number of type information interfaces provided by the object.</param>
|
|
/// <exception cref="T:System.NotImplementedException">The method is called late-bound using the COM IDispatch interface.</exception>
|
|
// Token: 0x06001A19 RID: 6681 RVA: 0x00062998 File Offset: 0x00060B98
|
|
void _FieldBuilder.GetTypeInfoCount(out uint pcTInfo)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
/// <summary>Provides access to properties and methods exposed by an object.</summary>
|
|
/// <param name="dispIdMember">Identifies the member.</param>
|
|
/// <param name="riid">Reserved for future use. Must be IID_NULL.</param>
|
|
/// <param name="lcid">The locale context in which to interpret arguments.</param>
|
|
/// <param name="wFlags">Flags describing the context of the call.</param>
|
|
/// <param name="pDispParams">Pointer to a structure containing an array of arguments, an array of argument DISPIDs for named arguments, and counts for the number of elements in the arrays.</param>
|
|
/// <param name="pVarResult">Pointer to the location where the result is to be stored.</param>
|
|
/// <param name="pExcepInfo">Pointer to a structure that contains exception information.</param>
|
|
/// <param name="puArgErr">The index of the first argument that has an error.</param>
|
|
/// <exception cref="T:System.NotImplementedException">The method is called late-bound using the COM IDispatch interface.</exception>
|
|
// Token: 0x06001A1A RID: 6682 RVA: 0x000629A0 File Offset: 0x00060BA0
|
|
void _FieldBuilder.Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
/// <summary>Indicates the attributes of this field. This property is read-only.</summary>
|
|
/// <returns>The attributes of this field.</returns>
|
|
// Token: 0x1700049A RID: 1178
|
|
// (get) Token: 0x06001A1B RID: 6683 RVA: 0x000629A8 File Offset: 0x00060BA8
|
|
public override FieldAttributes Attributes
|
|
{
|
|
get
|
|
{
|
|
return this.attrs;
|
|
}
|
|
}
|
|
|
|
/// <summary>Indicates a reference to the <see cref="T:System.Type" /> object for the type that declares this field. This property is read-only.</summary>
|
|
/// <returns>A reference to the <see cref="T:System.Type" /> object for the type that declares this field.</returns>
|
|
// Token: 0x1700049B RID: 1179
|
|
// (get) Token: 0x06001A1C RID: 6684 RVA: 0x000629B0 File Offset: 0x00060BB0
|
|
public override Type DeclaringType
|
|
{
|
|
get
|
|
{
|
|
return this.typeb;
|
|
}
|
|
}
|
|
|
|
/// <summary>Indicates the internal metadata handle for this field. This property is read-only.</summary>
|
|
/// <returns>The internal metadata handle for this field.</returns>
|
|
/// <exception cref="T:System.NotSupportedException">This method is not supported. </exception>
|
|
// Token: 0x1700049C RID: 1180
|
|
// (get) Token: 0x06001A1D RID: 6685 RVA: 0x000629B8 File Offset: 0x00060BB8
|
|
public override RuntimeFieldHandle FieldHandle
|
|
{
|
|
get
|
|
{
|
|
throw this.CreateNotSupportedException();
|
|
}
|
|
}
|
|
|
|
/// <summary>Indicates the <see cref="T:System.Type" /> object that represents the type of this field. This property is read-only.</summary>
|
|
/// <returns>The <see cref="T:System.Type" /> object that represents the type of this field.</returns>
|
|
// Token: 0x1700049D RID: 1181
|
|
// (get) Token: 0x06001A1E RID: 6686 RVA: 0x000629C0 File Offset: 0x00060BC0
|
|
public override Type FieldType
|
|
{
|
|
get
|
|
{
|
|
return this.type;
|
|
}
|
|
}
|
|
|
|
/// <summary>Indicates the name of this field. This property is read-only.</summary>
|
|
/// <returns>A <see cref="T:System.String" /> containing the name of this field.</returns>
|
|
// Token: 0x1700049E RID: 1182
|
|
// (get) Token: 0x06001A1F RID: 6687 RVA: 0x000629C8 File Offset: 0x00060BC8
|
|
public override string Name
|
|
{
|
|
get
|
|
{
|
|
return this.name;
|
|
}
|
|
}
|
|
|
|
/// <summary>Indicates the reference to the <see cref="T:System.Type" /> object from which this object was obtained. This property is read-only.</summary>
|
|
/// <returns>A reference to the <see cref="T:System.Type" /> object from which this instance was obtained.</returns>
|
|
// Token: 0x1700049F RID: 1183
|
|
// (get) Token: 0x06001A20 RID: 6688 RVA: 0x000629D0 File Offset: 0x00060BD0
|
|
public override Type ReflectedType
|
|
{
|
|
get
|
|
{
|
|
return this.typeb;
|
|
}
|
|
}
|
|
|
|
/// <summary>Returns all the custom attributes defined for this field.</summary>
|
|
/// <returns>An array of type <see cref="T:System.Object" /> representing all the custom attributes of the constructor represented by this <see cref="T:System.Reflection.Emit.FieldBuilder" /> instance.</returns>
|
|
/// <param name="inherit">Controls inheritance of custom attributes from base classes. </param>
|
|
/// <exception cref="T:System.NotSupportedException">This method is not supported. </exception>
|
|
// Token: 0x06001A21 RID: 6689 RVA: 0x000629D8 File Offset: 0x00060BD8
|
|
public override object[] GetCustomAttributes(bool inherit)
|
|
{
|
|
if (this.typeb.is_created)
|
|
{
|
|
return MonoCustomAttrs.GetCustomAttributes(this, inherit);
|
|
}
|
|
throw this.CreateNotSupportedException();
|
|
}
|
|
|
|
/// <summary>Returns all the custom attributes defined for this field identified by the given type.</summary>
|
|
/// <returns>An array of type <see cref="T:System.Object" /> representing all the custom attributes of the constructor represented by this <see cref="T:System.Reflection.Emit.FieldBuilder" /> instance.</returns>
|
|
/// <param name="attributeType">The custom attribute type. </param>
|
|
/// <param name="inherit">Controls inheritance of custom attributes from base classes. </param>
|
|
/// <exception cref="T:System.NotSupportedException">This method is not supported. </exception>
|
|
// Token: 0x06001A22 RID: 6690 RVA: 0x000629F8 File Offset: 0x00060BF8
|
|
public override object[] GetCustomAttributes(Type attributeType, bool inherit)
|
|
{
|
|
if (this.typeb.is_created)
|
|
{
|
|
return MonoCustomAttrs.GetCustomAttributes(this, attributeType, inherit);
|
|
}
|
|
throw this.CreateNotSupportedException();
|
|
}
|
|
|
|
/// <summary>Returns the token representing this field.</summary>
|
|
/// <returns>Returns the <see cref="T:System.Reflection.Emit.FieldToken" /> object that represents the token for this field.</returns>
|
|
// Token: 0x06001A23 RID: 6691 RVA: 0x00062A1C File Offset: 0x00060C1C
|
|
public FieldToken GetToken()
|
|
{
|
|
return new FieldToken(this.MetadataToken);
|
|
}
|
|
|
|
/// <summary>Retrieves the value of the field supported by the given object.</summary>
|
|
/// <returns>An <see cref="T:System.Object" /> containing the value of the field reflected by this instance.</returns>
|
|
/// <param name="obj">The object on which to access the field. </param>
|
|
/// <exception cref="T:System.NotSupportedException">This method is not supported. </exception>
|
|
// Token: 0x06001A24 RID: 6692 RVA: 0x00062A2C File Offset: 0x00060C2C
|
|
public override object GetValue(object obj)
|
|
{
|
|
throw this.CreateNotSupportedException();
|
|
}
|
|
|
|
/// <summary>Indicates whether an attribute having the specified type is defined on a field.</summary>
|
|
/// <returns>true if one or more instance of <paramref name="attributeType" /> is defined on this field; otherwise, false.</returns>
|
|
/// <param name="attributeType">The type of the attribute. </param>
|
|
/// <param name="inherit">Controls inheritance of custom attributes from base classes. </param>
|
|
/// <exception cref="T:System.NotSupportedException">This method is not currently supported. Retrieve the field using <see cref="M:System.Type.GetField(System.String,System.Reflection.BindingFlags)" /> and call <see cref="M:System.Reflection.MemberInfo.IsDefined(System.Type,System.Boolean)" /> on the returned <see cref="T:System.Reflection.FieldInfo" />. </exception>
|
|
// Token: 0x06001A25 RID: 6693 RVA: 0x00062A34 File Offset: 0x00060C34
|
|
public override bool IsDefined(Type attributeType, bool inherit)
|
|
{
|
|
throw this.CreateNotSupportedException();
|
|
}
|
|
|
|
// Token: 0x06001A26 RID: 6694 RVA: 0x00062A3C File Offset: 0x00060C3C
|
|
internal override int GetFieldOffset()
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
// Token: 0x06001A27 RID: 6695 RVA: 0x00062A40 File Offset: 0x00060C40
|
|
internal void SetRVAData(byte[] data)
|
|
{
|
|
this.rva_data = (byte[])data.Clone();
|
|
}
|
|
|
|
/// <summary>Sets the default value of this field.</summary>
|
|
/// <param name="defaultValue">The new default value for this field. </param>
|
|
/// <exception cref="T:System.InvalidOperationException">The containing type has been created using <see cref="M:System.Reflection.Emit.TypeBuilder.CreateType" />. </exception>
|
|
/// <exception cref="T:System.ArgumentException">The field is not one of the supported types.-or-The type of <paramref name="defaultValue" /> does not match the type of the field.-or-The field is of type <see cref="T:System.Object" /> or other reference type, and <paramref name="defaultValue" /> is not null.</exception>
|
|
// Token: 0x06001A28 RID: 6696 RVA: 0x00062A54 File Offset: 0x00060C54
|
|
public void SetConstant(object defaultValue)
|
|
{
|
|
this.RejectIfCreated();
|
|
this.def_value = defaultValue;
|
|
}
|
|
|
|
/// <summary>Sets a custom attribute using a custom attribute builder.</summary>
|
|
/// <param name="customBuilder">An instance of a helper class to define the custom attribute. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="con" /> is null. </exception>
|
|
/// <exception cref="T:System.InvalidOperationException">The parent type of this field is complete. </exception>
|
|
// Token: 0x06001A29 RID: 6697 RVA: 0x00062A64 File Offset: 0x00060C64
|
|
public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
|
|
{
|
|
this.RejectIfCreated();
|
|
string fullName = customBuilder.Ctor.ReflectedType.FullName;
|
|
if (fullName == "System.Runtime.InteropServices.FieldOffsetAttribute")
|
|
{
|
|
byte[] data = customBuilder.Data;
|
|
this.offset = (int)data[2];
|
|
this.offset |= (int)data[3] << 8;
|
|
this.offset |= (int)data[4] << 16;
|
|
this.offset |= (int)data[5] << 24;
|
|
return;
|
|
}
|
|
if (fullName == "System.NonSerializedAttribute")
|
|
{
|
|
this.attrs |= FieldAttributes.NotSerialized;
|
|
return;
|
|
}
|
|
if (fullName == "System.Runtime.CompilerServices.SpecialNameAttribute")
|
|
{
|
|
this.attrs |= FieldAttributes.SpecialName;
|
|
return;
|
|
}
|
|
if (fullName == "System.Runtime.InteropServices.MarshalAsAttribute")
|
|
{
|
|
this.attrs |= FieldAttributes.HasFieldMarshal;
|
|
this.marshal_info = CustomAttributeBuilder.get_umarshal(customBuilder, true);
|
|
return;
|
|
}
|
|
if (this.cattrs != null)
|
|
{
|
|
CustomAttributeBuilder[] array = new CustomAttributeBuilder[this.cattrs.Length + 1];
|
|
this.cattrs.CopyTo(array, 0);
|
|
array[this.cattrs.Length] = customBuilder;
|
|
this.cattrs = array;
|
|
}
|
|
else
|
|
{
|
|
this.cattrs = new CustomAttributeBuilder[1];
|
|
this.cattrs[0] = customBuilder;
|
|
}
|
|
}
|
|
|
|
/// <summary>Sets a custom attribute using a specified custom attribute blob.</summary>
|
|
/// <param name="con">The constructor for the custom attribute. </param>
|
|
/// <param name="binaryAttribute">A byte blob representing the attributes. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="con" /> or <paramref name="binaryAttribute" /> is null. </exception>
|
|
/// <exception cref="T:System.InvalidOperationException">The parent type of this field is complete. </exception>
|
|
// Token: 0x06001A2A RID: 6698 RVA: 0x00062BAC File Offset: 0x00060DAC
|
|
[ComVisible(true)]
|
|
public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
|
|
{
|
|
this.RejectIfCreated();
|
|
this.SetCustomAttribute(new CustomAttributeBuilder(con, binaryAttribute));
|
|
}
|
|
|
|
/// <summary>Describes the native marshaling of the field.</summary>
|
|
/// <param name="unmanagedMarshal">A descriptor specifying the native marshalling of this field. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">
|
|
/// <paramref name="unmanagedMarshal" /> is null. </exception>
|
|
/// <exception cref="T:System.InvalidOperationException">The containing type has been created using <see cref="M:System.Reflection.Emit.TypeBuilder.CreateType" />. </exception>
|
|
// Token: 0x06001A2B RID: 6699 RVA: 0x00062BC4 File Offset: 0x00060DC4
|
|
[Obsolete("An alternate API is available: Emit the MarshalAs custom attribute instead.")]
|
|
public void SetMarshal(UnmanagedMarshal unmanagedMarshal)
|
|
{
|
|
this.RejectIfCreated();
|
|
this.marshal_info = unmanagedMarshal;
|
|
this.attrs |= FieldAttributes.HasFieldMarshal;
|
|
}
|
|
|
|
/// <summary>Specifies the field layout.</summary>
|
|
/// <param name="iOffset">The offset of the field within the type containing this field. </param>
|
|
/// <exception cref="T:System.InvalidOperationException">The containing type has been created using <see cref="M:System.Reflection.Emit.TypeBuilder.CreateType" />. </exception>
|
|
/// <exception cref="T:System.ArgumentException">
|
|
/// <paramref name="iOffset" /> is less than zero.</exception>
|
|
// Token: 0x06001A2C RID: 6700 RVA: 0x00062BE8 File Offset: 0x00060DE8
|
|
public void SetOffset(int iOffset)
|
|
{
|
|
this.RejectIfCreated();
|
|
this.offset = iOffset;
|
|
}
|
|
|
|
/// <summary>Sets the value of the field supported by the given object.</summary>
|
|
/// <param name="obj">The object on which to access the field. </param>
|
|
/// <param name="val">The value to assign to the field. </param>
|
|
/// <param name="invokeAttr">A member of IBinder that specifies the type of binding that is desired (for example, IBinder.CreateInstance, IBinder.ExactBinding). </param>
|
|
/// <param name="binder">A set of properties and enabling for binding, coercion of argument types, and invocation of members using reflection. If binder is null, then IBinder.DefaultBinding is used. </param>
|
|
/// <param name="culture">The software preferences of a particular culture. </param>
|
|
/// <exception cref="T:System.NotSupportedException">This method is not supported. </exception>
|
|
// Token: 0x06001A2D RID: 6701 RVA: 0x00062BF8 File Offset: 0x00060DF8
|
|
public override void SetValue(object obj, object val, BindingFlags invokeAttr, Binder binder, CultureInfo culture)
|
|
{
|
|
throw this.CreateNotSupportedException();
|
|
}
|
|
|
|
// Token: 0x170004A0 RID: 1184
|
|
// (get) Token: 0x06001A2E RID: 6702 RVA: 0x00062C00 File Offset: 0x00060E00
|
|
internal override UnmanagedMarshal UMarshal
|
|
{
|
|
get
|
|
{
|
|
return this.marshal_info;
|
|
}
|
|
}
|
|
|
|
// Token: 0x06001A2F RID: 6703 RVA: 0x00062C08 File Offset: 0x00060E08
|
|
private Exception CreateNotSupportedException()
|
|
{
|
|
return new NotSupportedException("The invoked member is not supported in a dynamic module.");
|
|
}
|
|
|
|
// Token: 0x06001A30 RID: 6704 RVA: 0x00062C14 File Offset: 0x00060E14
|
|
private void RejectIfCreated()
|
|
{
|
|
if (this.typeb.is_created)
|
|
{
|
|
throw new InvalidOperationException("Unable to change after type has been created.");
|
|
}
|
|
}
|
|
|
|
/// <summary>Gets the module in which the type that contains this field is being defined.</summary>
|
|
/// <returns>A <see cref="T:System.Reflection.Module" /> that represents the dynamic module in which this field is being defined.</returns>
|
|
// Token: 0x170004A1 RID: 1185
|
|
// (get) Token: 0x06001A31 RID: 6705 RVA: 0x00062C34 File Offset: 0x00060E34
|
|
public override Module Module
|
|
{
|
|
get
|
|
{
|
|
return base.Module;
|
|
}
|
|
}
|
|
|
|
// Token: 0x040007B2 RID: 1970
|
|
private FieldAttributes attrs;
|
|
|
|
// Token: 0x040007B3 RID: 1971
|
|
private Type type;
|
|
|
|
// Token: 0x040007B4 RID: 1972
|
|
private string name;
|
|
|
|
// Token: 0x040007B5 RID: 1973
|
|
private object def_value;
|
|
|
|
// Token: 0x040007B6 RID: 1974
|
|
private int offset;
|
|
|
|
// Token: 0x040007B7 RID: 1975
|
|
private int table_idx;
|
|
|
|
// Token: 0x040007B8 RID: 1976
|
|
internal TypeBuilder typeb;
|
|
|
|
// Token: 0x040007B9 RID: 1977
|
|
private byte[] rva_data;
|
|
|
|
// Token: 0x040007BA RID: 1978
|
|
private CustomAttributeBuilder[] cattrs;
|
|
|
|
// Token: 0x040007BB RID: 1979
|
|
private UnmanagedMarshal marshal_info;
|
|
|
|
// Token: 0x040007BC RID: 1980
|
|
private RuntimeFieldHandle handle;
|
|
|
|
// Token: 0x040007BD RID: 1981
|
|
private Type[] modReq;
|
|
|
|
// Token: 0x040007BE RID: 1982
|
|
private Type[] modOpt;
|
|
}
|
|
}
|