TypeBuilder.DefineCustomAttribute(
_manifestModuleBuilder, // pass in the in-memory assembly module
AssemblyBuilderData.AssemblyDefToken,
- _manifestModuleBuilder.GetConstructorToken(con).Token,
+ _manifestModuleBuilder.GetConstructorToken(con),
binaryAttribute,
false,
typeof(DebuggableAttribute) == con.DeclaringType);
m_methodBuilder.GetMethodSignature().InternalGetSignature(out _);
- m_methodBuilder.GetToken();
+ int dummy = m_methodBuilder.MetadataToken;
}
internal ConstructorBuilder(string name, MethodAttributes attributes, CallingConventions callingConvention,
#endregion
#region MemberInfo Overrides
- internal int MetadataTokenInternal => m_methodBuilder.MetadataTokenInternal;
+ public override int MetadataToken => m_methodBuilder.MetadataToken;
public override Module Module => m_methodBuilder.Module;
#endregion
#region Public Members
- public MethodToken GetToken()
- {
- return m_methodBuilder.GetToken();
- }
-
public ParameterBuilder DefineParameter(int iSequence, ParameterAttributes attributes, string? strParamName)
{
// Theoretically we shouldn't allow iSequence to be 0 because in reflection ctors don't have
// return the byte interpretation of the custom attribute
internal void CreateCustomAttribute(ModuleBuilder mod, int tkOwner)
{
- CreateCustomAttribute(mod, tkOwner, mod.GetConstructorToken(m_con).Token, false);
+ CreateCustomAttribute(mod, tkOwner, mod.GetConstructorToken(m_con), false);
}
/// <summary>
}
// Get the internal metadata token for this class.
- public TypeToken TypeToken => m_typeBuilder.TypeToken;
+ internal int TypeToken => m_typeBuilder.TypeToken;
// return the underlying field for the enum
EventAttributes attr, // event attribute such as Public, Private, and Protected defined above
// int eventType, // event type
TypeBuilder type, // containing type
- EventToken evToken)
+ int evToken)
{
m_name = name;
m_module = mod;
// Return the Token for this event within the TypeBuilder that the
// event is defined within.
- public EventToken GetEventToken()
+ internal int GetEventToken()
{
return m_evToken;
}
ModuleBuilder module = m_module;
TypeBuilder.DefineMethodSemantics(
new QCallModule(ref module),
- m_evToken.Token,
+ m_evToken,
semantics,
- mdBuilder.GetToken().Token);
+ mdBuilder.MetadataToken);
}
public void SetAddOnMethod(MethodBuilder mdBuilder)
TypeBuilder.DefineCustomAttribute(
m_module,
- m_evToken.Token,
- m_module.GetConstructorToken(con).Token,
+ m_evToken,
+ m_module.GetConstructorToken(con),
binaryAttribute,
false, false);
}
throw new ArgumentNullException(nameof(customBuilder));
}
m_type.ThrowIfCreated();
- customBuilder.CreateCustomAttribute(m_module, m_evToken.Token);
+ customBuilder.CreateCustomAttribute(m_module, m_evToken);
}
// These are package private so that TypeBuilder can access them.
private string m_name; // The name of the event
- private EventToken m_evToken; // The token of this event
+ private int m_evToken; // The token of this event
private ModuleBuilder m_module;
private EventAttributes m_attributes;
private TypeBuilder m_type;
{
#region Private Data Members
private int m_fieldTok;
- private FieldToken m_tkField;
private TypeBuilder m_typeBuilder;
private string m_fieldName;
private FieldAttributes m_Attributes;
ModuleBuilder module = m_typeBuilder.GetModuleBuilder();
m_fieldTok = TypeBuilder.DefineField(new QCallModule(ref module),
- typeBuilder.TypeToken.Token, fieldName, signature, sigLength, m_Attributes);
-
- m_tkField = new FieldToken(m_fieldTok, type);
+ typeBuilder.TypeToken, fieldName, signature, sigLength, m_Attributes);
}
#endregion
internal void SetData(byte[]? data, int size)
{
ModuleBuilder module = m_typeBuilder.GetModuleBuilder();
- ModuleBuilder.SetFieldRVAContent(new QCallModule(ref module), m_tkField.Token, data, size);
+ ModuleBuilder.SetFieldRVAContent(new QCallModule(ref module), m_fieldTok, data, size);
}
#endregion
#region MemberInfo Overrides
- internal int MetadataTokenInternal => m_fieldTok;
+ public override int MetadataToken => m_fieldTok;
public override Module Module => m_typeBuilder.Module;
#endregion
#region Public Members
- public FieldToken GetToken()
- {
- return m_tkField;
- }
-
public void SetOffset(int iOffset)
{
m_typeBuilder.ThrowIfCreated();
ModuleBuilder module = m_typeBuilder.GetModuleBuilder();
- TypeBuilder.SetFieldLayoutOffset(new QCallModule(ref module), GetToken().Token, iOffset);
+ TypeBuilder.SetFieldLayoutOffset(new QCallModule(ref module), m_fieldTok, iOffset);
}
public void SetConstant(object? defaultValue)
throw new ArgumentException(SR.Argument_ConstantNull);
}
- TypeBuilder.SetConstantValue(m_typeBuilder.GetModuleBuilder(), GetToken().Token, m_fieldType, defaultValue);
+ TypeBuilder.SetConstantValue(m_typeBuilder.GetModuleBuilder(), m_fieldTok, m_fieldType, defaultValue);
}
public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
m_typeBuilder.ThrowIfCreated();
TypeBuilder.DefineCustomAttribute(module,
- m_tkField.Token, module.GetConstructorToken(con).Token, binaryAttribute, false, false);
+ m_fieldTok, module.GetConstructorToken(con), binaryAttribute, false, false);
}
public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
ModuleBuilder? module = m_typeBuilder.Module as ModuleBuilder;
- customBuilder.CreateCustomAttribute(module!, m_tkField.Token);
+ customBuilder.CreateCustomAttribute(module!, m_fieldTok);
}
#endregion
public override bool IsByRefLike => false;
- internal int MetadataTokenInternal => m_type.MetadataTokenInternal;
+ public override int MetadataToken => m_type.MetadataToken;
#endregion
#region Type Overrides
UpdateStackSize(OpCodes.Calli, stackchange);
RecordTokenFixup();
- PutInteger4(modBuilder.GetSignatureToken(sig).Token);
+ PutInteger4(modBuilder.GetSignatureToken(sig));
}
public virtual void EmitCalli(OpCode opcode, CallingConvention unmanagedCallConv, Type? returnType, Type[]? parameterTypes)
EnsureCapacity(7);
Emit(OpCodes.Calli);
RecordTokenFixup();
- PutInteger4(modBuilder.GetSignatureToken(sig).Token);
+ PutInteger4(modBuilder.GetSignatureToken(sig));
}
public virtual void EmitCall(OpCode opcode, MethodInfo methodInfo, Type[]? optionalParameterTypes)
int stackchange = 0;
ModuleBuilder modBuilder = (ModuleBuilder)m_methodBuilder.Module;
- SignatureToken sig = modBuilder.GetSignatureToken(signature);
+ int sig = modBuilder.GetSignatureToken(signature);
- int tempVal = sig.Token;
+ int tempVal = sig;
EnsureCapacity(7);
InternalEmit(opcode);
if (opcode == OpCodes.Ldtoken && cls != null && cls.IsGenericTypeDefinition)
{
// This gets the token for the generic type definition if cls is one.
- tempVal = modBuilder.GetTypeToken(cls).Token;
+ tempVal = modBuilder.GetTypeToken(cls);
}
else
{
// This gets the token for the generic type instantiated on the formal parameters
// if cls is a generic type definition.
- tempVal = modBuilder.GetTypeTokenInternal(cls!).Token;
+ tempVal = modBuilder.GetTypeTokenInternal(cls!);
}
EnsureCapacity(7);
public virtual void Emit(OpCode opcode, FieldInfo field)
{
ModuleBuilder modBuilder = (ModuleBuilder)m_methodBuilder.Module;
- int tempVal = modBuilder.GetFieldToken(field).Token;
+ int tempVal = modBuilder.GetFieldToken(field);
EnsureCapacity(7);
InternalEmit(opcode);
RecordTokenFixup();
// fixups if the module is persisted to a PE.
ModuleBuilder modBuilder = (ModuleBuilder)m_methodBuilder.Module;
- int tempVal = modBuilder.GetStringConstant(str).Token;
+ int tempVal = modBuilder.GetStringConstant(str);
EnsureCapacity(7);
InternalEmit(opcode);
PutInteger4(tempVal);
#region Private Data Members
// Identity
internal string m_strName; // The name of the method
- private MethodToken m_tkMethod; // The token of this method
+ private int m_token; // The token of this method
private readonly ModuleBuilder m_module;
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
int tkExceptionClass = 0;
if (catchClass[j] != null)
{
- tkExceptionClass = dynMod.GetTypeTokenInternal(catchClass[j]).Token;
+ tkExceptionClass = dynMod.GetTypeTokenInternal(catchClass[j]);
}
switch (type[j])
// set the debugging information such as scope and line number
// if it is in a debug module
//
- SymbolToken tk = new SymbolToken(MetadataTokenInternal);
+ SymbolToken tk = new SymbolToken(MetadataToken);
ISymbolWriter symWriter = dynMod.GetSymWriter()!;
// call OpenMethod to make this method the current method
}
}
- internal void SetToken(MethodToken token)
+ internal void SetToken(int token)
{
- m_tkMethod = token;
+ m_token = token;
}
internal byte[]? GetBody()
#region MemberInfo Overrides
public override string Name => m_strName;
- internal int MetadataTokenInternal => GetToken().Token;
+ public override int MetadataToken => GetToken();
public override Module Module => m_containingType.Module;
if (names[i] == null)
throw new ArgumentNullException(nameof(names));
- if (m_tkMethod.Token != 0)
+ if (m_token != 0)
throw new InvalidOperationException(SR.InvalidOperation_MethodBuilderBaked);
m_bIsGenMethDef = true;
#endregion
#region Public Members
- public MethodToken GetToken()
+ private int GetToken()
{
// We used to always "tokenize" a MethodBuilder when it is constructed. After change list 709498
// we only "tokenize" a method when requested. But the order in which the methods are tokenized
// I don't fully understand this change. So I will keep the logic and only fix the recursion and
// the race condition.
- if (m_tkMethod.Token != 0)
+ if (m_token != 0)
{
- return m_tkMethod;
+ return m_token;
}
MethodBuilder? currentMethod = null;
- MethodToken currentToken = new MethodToken(0);
+ int currentToken = 0;
int i;
// We need to lock here to prevent a method from being "tokenized" twice.
// constructed MethodBuilders to the end of m_listMethods
lock (m_containingType.m_listMethods!)
{
- if (m_tkMethod.Token != 0)
+ if (m_token != 0)
{
- return m_tkMethod;
+ return m_token;
}
// If m_tkMethod is still 0 when we obtain the lock, m_lastTokenizedMethod must be smaller
}
Debug.Assert(currentMethod == this, "We should have found this method in m_containingType.m_listMethods");
- Debug.Assert(currentToken.Token != 0, "The token should not be 0");
+ Debug.Assert(currentToken != 0, "The token should not be 0");
return currentToken;
}
- private MethodToken GetTokenNoLock()
+ private int GetTokenNoLock()
{
- Debug.Assert(m_tkMethod.Token == 0, "m_tkMethod should not have been initialized");
+ Debug.Assert(m_token == 0, "m_token should not have been initialized");
byte[] sigBytes = GetMethodSignature().InternalGetSignature(out int sigLength);
ModuleBuilder module = m_module;
- int token = TypeBuilder.DefineMethod(new QCallModule(ref module), m_containingType.MetadataTokenInternal, m_strName, sigBytes, sigLength, Attributes);
- m_tkMethod = new MethodToken(token);
+ int token = TypeBuilder.DefineMethod(new QCallModule(ref module), m_containingType.MetadataToken, m_strName, sigBytes, sigLength, Attributes);
+ m_token = token;
if (m_inst != null)
foreach (GenericTypeParameterBuilder tb in m_inst)
TypeBuilder.SetMethodImpl(new QCallModule(ref module), token, m_dwMethodImplFlags);
- return m_tkMethod;
+ return m_token;
}
public void SetParameters(params Type[] parameterTypes)
{
// We should throw InvalidOperation_MethodBuilderBaked here if the method signature has been baked.
// But we cannot because that would be a breaking change from V2.
- if (m_tkMethod.Token != 0)
+ if (m_token != 0)
return;
AssemblyBuilder.CheckContext(returnType);
m_canBeRuntimeImpl = true;
ModuleBuilder module = m_module;
- TypeBuilder.SetMethodImpl(new QCallModule(ref module), MetadataTokenInternal, attributes);
+ TypeBuilder.SetMethodImpl(new QCallModule(ref module), MetadataToken, attributes);
}
public ILGenerator GetILGenerator()
ThrowIfGeneric();
- TypeBuilder.DefineCustomAttribute(m_module, MetadataTokenInternal,
- ((ModuleBuilder)m_module).GetConstructorToken(con).Token,
+ TypeBuilder.DefineCustomAttribute(m_module, MetadataToken,
+ ((ModuleBuilder)m_module).GetConstructorToken(con),
binaryAttribute,
false, false);
ThrowIfGeneric();
- customBuilder.CreateCustomAttribute((ModuleBuilder)m_module, MetadataTokenInternal);
+ customBuilder.CreateCustomAttribute((ModuleBuilder)m_module, MetadataToken);
if (IsKnownCA(customBuilder.m_con))
ParseCA(customBuilder.m_con);
return GetTypeRef(new QCallModule(ref thisModule), typeName, new QCallModule(ref refedRuntimeModule), strRefedModuleFileName, tkResolution);
}
- internal MethodToken InternalGetConstructorToken(ConstructorInfo con, bool usingRef)
+ internal int InternalGetConstructorToken(ConstructorInfo con, bool usingRef)
{
// Helper to get constructor token. If usingRef is true, we will never use the def token
if (con == null)
}
int tr;
- int mr = 0;
+ int mr;
if (con is ConstructorBuilder conBuilder)
{
if (!usingRef && conBuilder.Module.Equals(this))
- return conBuilder.GetToken();
+ return conBuilder.MetadataToken;
// constructor is defined in a different module
- tr = GetTypeTokenInternal(con.ReflectedType!).Token;
- mr = GetMemberRef(con.ReflectedType!.Module, tr, conBuilder.GetToken().Token);
+ tr = GetTypeTokenInternal(con.ReflectedType!);
+ mr = GetMemberRef(con.ReflectedType!.Module, tr, conBuilder.MetadataToken);
}
else if (con is ConstructorOnTypeBuilderInstantiation conOnTypeBuilderInst)
{
if (usingRef) throw new InvalidOperationException();
- tr = GetTypeTokenInternal(con.DeclaringType!).Token;
- mr = GetMemberRef(con.DeclaringType!.Module, tr, conOnTypeBuilderInst.MetadataTokenInternal);
+ tr = GetTypeTokenInternal(con.DeclaringType!);
+ mr = GetMemberRef(con.DeclaringType!.Module, tr, conOnTypeBuilderInst.MetadataToken);
}
else if (con is RuntimeConstructorInfo rtCon && !con.ReflectedType!.IsArray)
{
// constructor is not a dynamic field
// We need to get the TypeRef tokens
- tr = GetTypeTokenInternal(con.ReflectedType).Token;
+ tr = GetTypeTokenInternal(con.ReflectedType);
mr = GetMemberRefOfMethodInfo(tr, rtCon);
}
else
optionalCustomModifiers[i] = parameters[i].GetOptionalCustomModifiers();
}
- tr = GetTypeTokenInternal(con.ReflectedType!).Token;
+ tr = GetTypeTokenInternal(con.ReflectedType!);
SignatureHelper sigHelp = SignatureHelper.GetMethodSigHelper(this, con.CallingConvention, null, null, null, parameterTypes, requiredCustomModifiers, optionalCustomModifiers);
byte[] sigBytes = sigHelp.InternalGetSignature(out int length);
mr = GetMemberRefFromSignature(tr, con.Name, sigBytes, length);
}
- return new MethodToken(mr);
+ return mr;
}
internal void Init(string strModuleName)
else if (!method.Module.Equals(this))
{
// Use typeRef as parent because the method's declaringType lives in a different assembly
- tkParent = GetTypeToken(method.DeclaringType).Token;
+ tkParent = GetTypeToken(method.DeclaringType);
}
else
{
// Use methodDef as parent because the method lives in this assembly and its declaringType has no generic arguments
if (masmi != null)
- tkParent = GetMethodToken(masmi).Token;
+ tkParent = GetMethodToken(masmi);
else
- tkParent = GetConstructorToken((method as ConstructorInfo)!).Token;
+ tkParent = GetConstructorToken((method as ConstructorInfo)!);
}
return GetMemberRefFromSignature(tkParent, method.Name, sigBytes, sigLength);
// 1. GetTypeToken
// 2. ldtoken (see ILGenerator)
// For all other occasions we should return the generic type instantiated on its formal parameters.
- internal TypeToken GetTypeTokenInternal(Type type)
+ internal int GetTypeTokenInternal(Type type)
{
return GetTypeTokenInternal(type, getGenericDefinition: false);
}
- private TypeToken GetTypeTokenInternal(Type type, bool getGenericDefinition)
+ private int GetTypeTokenInternal(Type type, bool getGenericDefinition)
{
lock (SyncRoot)
{
}
}
- public TypeToken GetTypeToken(Type type)
+ internal int GetTypeToken(Type type)
{
return GetTypeTokenInternal(type, getGenericDefinition: true);
}
- private TypeToken GetTypeTokenWorkerNoLock(Type type, bool getGenericDefinition)
+ private int GetTypeTokenWorkerNoLock(Type type, bool getGenericDefinition)
{
if (type == null)
{
type.IsPointer)
{
byte[] sig = SignatureHelper.GetTypeSigToken(this, type).InternalGetSignature(out int length);
- return new TypeToken(GetTokenFromTypeSpec(sig, length));
+ return GetTokenFromTypeSpec(sig, length);
}
Module refedModule = type.Module;
}
else if (type is GenericTypeParameterBuilder paramBuilder)
{
- return new TypeToken(paramBuilder.MetadataTokenInternal);
+ return paramBuilder.MetadataToken;
}
- return new TypeToken(GetTypeRefNested(type, this, string.Empty));
+ return GetTypeRefNested(type, this, string.Empty);
}
// After this point, the referenced module is not the same as the referencing
referencedModuleFileName = refedModuleBuilder._moduleData._moduleName;
}
- return new TypeToken(GetTypeRefNested(type, refedModule, referencedModuleFileName));
+ return GetTypeRefNested(type, refedModule, referencedModuleFileName);
}
- public TypeToken GetTypeToken(string name)
+ internal int GetTypeToken(string name)
{
// Return a token for the class relative to the Module.
// Module.GetType() verifies name
return GetTypeToken(InternalModule.GetType(name, false, true)!);
}
- public MethodToken GetMethodToken(MethodInfo method)
- {
- lock (SyncRoot)
- {
- return GetMethodTokenNoLock(method, true);
- }
- }
-
- internal MethodToken GetMethodTokenInternal(MethodInfo method)
+ internal int GetMethodToken(MethodInfo method)
{
lock (SyncRoot)
{
// 1. GetMethodToken
// 2. ldtoken (see ILGenerator)
// For all other occasions we should return the method on the generic type instantiated on the formal parameters.
- private MethodToken GetMethodTokenNoLock(MethodInfo method, bool getGenericTypeDefinition)
+ private int GetMethodTokenNoLock(MethodInfo method, bool getGenericTypeDefinition)
{
// Return a MemberRef token if MethodInfo is not defined in this module. Or
// return the MethodDef token.
if (method is MethodBuilder methBuilder)
{
- int methodToken = methBuilder.MetadataTokenInternal;
+ int methodToken = methBuilder.MetadataToken;
if (method.Module.Equals(this))
{
- return new MethodToken(methodToken);
+ return methodToken;
}
if (method.DeclaringType == null)
}
// method is defined in a different module
- tr = getGenericTypeDefinition ? GetTypeToken(method.DeclaringType).Token : GetTypeTokenInternal(method.DeclaringType).Token;
+ tr = getGenericTypeDefinition ? GetTypeToken(method.DeclaringType) : GetTypeTokenInternal(method.DeclaringType);
mr = GetMemberRef(method.DeclaringType.Module, tr, methodToken);
}
else if (method is MethodOnTypeBuilderInstantiation)
{
- return new MethodToken(GetMemberRefToken(method, null));
+ return GetMemberRefToken(method, null);
}
else if (method is SymbolMethod symMethod)
{
if (symMethod.GetModule() == this)
- return symMethod.GetToken();
+ return symMethod.MetadataToken;
// form the method token
return symMethod.GetToken(this);
}
else if (method is RuntimeMethodInfo rtMeth)
{
- tr = getGenericTypeDefinition ? GetTypeToken(declaringType).Token : GetTypeTokenInternal(declaringType).Token;
+ tr = getGenericTypeDefinition ? GetTypeToken(declaringType) : GetTypeTokenInternal(declaringType);
mr = GetMemberRefOfMethodInfo(tr, rtMeth);
}
else
optionalCustomModifiers[i] = parameters[i].GetOptionalCustomModifiers();
}
- tr = getGenericTypeDefinition ? GetTypeToken(declaringType).Token : GetTypeTokenInternal(declaringType).Token;
+ tr = getGenericTypeDefinition ? GetTypeToken(declaringType) : GetTypeTokenInternal(declaringType);
SignatureHelper sigHelp;
}
}
- return new MethodToken(mr);
+ return mr;
}
internal int GetMethodTokenInternal(MethodBase method, Type[]? optionalParameterTypes, bool useMethodDef)
}
else
{
- tk = GetMethodTokenInternal(methodInfoUnbound).Token;
+ tk = GetMethodToken(methodInfoUnbound);
}
// For Ldtoken, Ldftn, and Ldvirtftn, we should emit the method def/ref token for a generic method definition.
{
if (methodInfo != null)
{
- tk = GetMethodTokenInternal(methodInfo).Token;
+ tk = GetMethodToken(methodInfo);
}
else
{
- tk = GetConstructorToken((method as ConstructorInfo)!).Token;
+ tk = GetConstructorToken((method as ConstructorInfo)!);
}
}
else
return tk;
}
- public MethodToken GetArrayMethodToken(Type arrayClass, string methodName, CallingConventions callingConvention,
+ internal int GetArrayMethodToken(Type arrayClass, string methodName, CallingConventions callingConvention,
Type? returnType, Type[]? parameterTypes)
{
lock (SyncRoot)
}
}
- private MethodToken GetArrayMethodTokenNoLock(Type arrayClass, string methodName, CallingConventions callingConvention,
+ private int GetArrayMethodTokenNoLock(Type arrayClass, string methodName, CallingConventions callingConvention,
Type? returnType, Type[]? parameterTypes)
{
if (arrayClass == null)
SignatureHelper sigHelp = SignatureHelper.GetMethodSigHelper(
this, callingConvention, returnType, null, null, parameterTypes, null, null);
byte[] sigBytes = sigHelp.InternalGetSignature(out int length);
- TypeToken typeSpec = GetTypeTokenInternal(arrayClass);
+ int typeSpec = GetTypeTokenInternal(arrayClass);
ModuleBuilder thisModule = this;
- return new MethodToken(GetArrayMethodToken(new QCallModule(ref thisModule),
- typeSpec.Token, methodName, sigBytes, length));
+ return GetArrayMethodToken(new QCallModule(ref thisModule),
+ typeSpec, methodName, sigBytes, length);
}
public MethodInfo GetArrayMethod(Type arrayClass, string methodName, CallingConventions callingConvention,
// method that takes an array of the type as a parameter. In order to access the elements of the array,
// you will need to call methods of the Array class.
- MethodToken token = GetArrayMethodToken(arrayClass, methodName, callingConvention, returnType, parameterTypes);
+ int token = GetArrayMethodToken(arrayClass, methodName, callingConvention, returnType, parameterTypes);
return new SymbolMethod(this, token, arrayClass, methodName, callingConvention, returnType, parameterTypes);
}
- public MethodToken GetConstructorToken(ConstructorInfo con)
+ internal int GetConstructorToken(ConstructorInfo con)
{
// Return a token for the ConstructorInfo relative to the Module.
return InternalGetConstructorToken(con, false);
}
- public FieldToken GetFieldToken(FieldInfo field)
+ internal int GetFieldToken(FieldInfo field)
{
lock (SyncRoot)
{
}
}
- private FieldToken GetFieldTokenNoLock(FieldInfo field)
+ private int GetFieldTokenNoLock(FieldInfo field)
{
if (field == null)
{
{
byte[] sig = SignatureHelper.GetTypeSigToken(this, field.DeclaringType).InternalGetSignature(out int length);
tr = GetTokenFromTypeSpec(sig, length);
- mr = GetMemberRef(this, tr, fdBuilder.GetToken().Token);
+ mr = GetMemberRef(this, tr, fdBuilder.MetadataToken);
}
else if (fdBuilder.Module.Equals(this))
{
// field is defined in the same module
- return fdBuilder.GetToken();
+ return fdBuilder.MetadataToken;
}
else
{
{
throw new InvalidOperationException(SR.InvalidOperation_CannotImportGlobalFromDifferentModule);
}
- tr = GetTypeTokenInternal(field.DeclaringType).Token;
- mr = GetMemberRef(field.ReflectedType!.Module, tr, fdBuilder.GetToken().Token);
+ tr = GetTypeTokenInternal(field.DeclaringType);
+ mr = GetMemberRef(field.ReflectedType!.Module, tr, fdBuilder.MetadataToken);
}
}
else if (field is RuntimeFieldInfo rtField)
}
else
{
- tr = GetTypeTokenInternal(field.DeclaringType!).Token;
+ tr = GetTypeTokenInternal(field.DeclaringType!);
mr = GetMemberRefOfFieldInfo(tr, field.DeclaringType!.GetTypeHandleInternal(), rtField);
}
}
FieldInfo fb = fOnTB.FieldInfo;
byte[] sig = SignatureHelper.GetTypeSigToken(this, field.DeclaringType!).InternalGetSignature(out int length);
tr = GetTokenFromTypeSpec(sig, length);
- mr = GetMemberRef(fb.ReflectedType!.Module, tr, fOnTB.MetadataTokenInternal);
+ mr = GetMemberRef(fb.ReflectedType!.Module, tr, fOnTB.MetadataToken);
}
else
{
// user defined FieldInfo
- tr = GetTypeTokenInternal(field.ReflectedType!).Token;
+ tr = GetTypeTokenInternal(field.ReflectedType!);
SignatureHelper sigHelp = SignatureHelper.GetFieldSigHelper(this);
mr = GetMemberRefFromSignature(tr, field.Name, sigBytes, length);
}
- return new FieldToken(mr, field.GetType());
+ return mr;
}
- public StringToken GetStringConstant(string str)
+ internal int GetStringConstant(string str)
{
if (str == null)
{
// Returns a token representing a String constant. If the string
// value has already been defined, the existing token will be returned.
ModuleBuilder thisModule = this;
- return new StringToken(GetStringConstant(new QCallModule(ref thisModule), str, str.Length));
+ return GetStringConstant(new QCallModule(ref thisModule), str, str.Length);
}
- public SignatureToken GetSignatureToken(SignatureHelper sigHelper)
+ internal int GetSignatureToken(SignatureHelper sigHelper)
{
// Define signature token given a signature helper. This will define a metadata
// token for the signature described by SignatureHelper.
// get the signature in byte form
byte[] sigBytes = sigHelper.InternalGetSignature(out int sigLength);
ModuleBuilder thisModule = this;
- return new SignatureToken(TypeBuilder.GetTokenFromSig(new QCallModule(ref thisModule), sigBytes, sigLength));
+ return TypeBuilder.GetTokenFromSig(new QCallModule(ref thisModule), sigBytes, sigLength);
}
- public SignatureToken GetSignatureToken(byte[] sigBytes, int sigLength)
+ internal int GetSignatureToken(byte[] sigBytes, int sigLength)
{
if (sigBytes == null)
{
Buffer.BlockCopy(sigBytes, 0, localSigBytes, 0, sigBytes.Length);
ModuleBuilder thisModule = this;
- return new SignatureToken(TypeBuilder.GetTokenFromSig(new QCallModule(ref thisModule), localSigBytes, sigLength));
+ return TypeBuilder.GetTokenFromSig(new QCallModule(ref thisModule), localSigBytes, sigLength);
}
#endregion
TypeBuilder.DefineCustomAttribute(
this,
1, // This is hard coding the module token to 1
- GetConstructorToken(con).Token,
+ GetConstructorToken(con),
binaryAttribute,
false, false);
}
{
TypeBuilder.SetConstantValue(
_methodBuilder.GetModuleBuilder(),
- _token.Token,
+ _token,
_position == 0 ? _methodBuilder.ReturnType : _methodBuilder.m_parameterTypes![_position - 1],
defaultValue);
}
TypeBuilder.DefineCustomAttribute(
_methodBuilder.GetModuleBuilder(),
- _token.Token,
- ((ModuleBuilder)_methodBuilder.GetModule()).GetConstructorToken(con).Token,
+ _token,
+ ((ModuleBuilder)_methodBuilder.GetModule()).GetConstructorToken(con),
binaryAttribute,
false, false);
}
{
throw new ArgumentNullException(nameof(customBuilder));
}
- customBuilder.CreateCustomAttribute((ModuleBuilder)(_methodBuilder.GetModule()), _token.Token);
+ customBuilder.CreateCustomAttribute((ModuleBuilder)(_methodBuilder.GetModule()), _token);
}
internal ParameterBuilder(
_methodBuilder = methodBuilder;
_attributes = attributes;
ModuleBuilder module = _methodBuilder.GetModuleBuilder();
- _token = new ParameterToken(TypeBuilder.SetParamInfo(
+ _token = TypeBuilder.SetParamInfo(
new QCallModule(ref module),
- _methodBuilder.GetToken().Token,
+ _methodBuilder.MetadataToken,
sequence,
attributes,
- paramName));
+ paramName);
}
- public virtual ParameterToken GetToken()
+ internal int GetToken()
{
return _token;
}
private readonly int _position;
private readonly ParameterAttributes _attributes;
private MethodBuilder _methodBuilder;
- private ParameterToken _token;
+ private int _token;
}
}
// Constructs a PropertyBuilder.
//
internal PropertyBuilder(
- ModuleBuilder mod, // the module containing this PropertyBuilder
- string name, // property name
- SignatureHelper sig, // property signature descriptor info
- PropertyAttributes attr, // property attribute such as DefaultProperty, Bindable, DisplayBind, etc
- Type returnType, // return type of the property.
- PropertyToken prToken, // the metadata token for this property
+ ModuleBuilder mod, // the module containing this PropertyBuilder
+ string name, // property name
+ SignatureHelper sig, // property signature descriptor info
+ PropertyAttributes attr, // property attribute such as DefaultProperty, Bindable, DisplayBind, etc
+ Type returnType, // return type of the property.
+ int prToken, // the metadata token for this property
TypeBuilder containingType) // the containing type
{
if (name == null)
m_name = name;
m_moduleBuilder = mod;
- m_signature = sig;
m_attributes = attr;
m_returnType = returnType;
- m_prToken = prToken;
- m_tkProperty = prToken.Token;
+ m_tkProperty = prToken;
m_containingType = containingType;
}
TypeBuilder.SetConstantValue(
m_moduleBuilder,
- m_prToken.Token,
+ m_tkProperty,
m_returnType,
defaultValue);
}
// Return the Token for this property within the TypeBuilder that the
// property is defined within.
- public PropertyToken PropertyToken => m_prToken;
+ internal int PropertyToken => m_tkProperty;
public override Module Module => m_containingType.Module;
ModuleBuilder module = m_moduleBuilder;
TypeBuilder.DefineMethodSemantics(
new QCallModule(ref module),
- m_prToken.Token,
+ m_tkProperty,
semantics,
- mdBuilder.GetToken().Token);
+ mdBuilder.MetadataToken);
}
public void SetGetMethod(MethodBuilder mdBuilder)
m_containingType.ThrowIfCreated();
TypeBuilder.DefineCustomAttribute(
m_moduleBuilder,
- m_prToken.Token,
- m_moduleBuilder.GetConstructorToken(con).Token,
+ m_tkProperty,
+ m_moduleBuilder.GetConstructorToken(con),
binaryAttribute,
false, false);
}
throw new ArgumentNullException(nameof(customBuilder));
}
m_containingType.ThrowIfCreated();
- customBuilder.CreateCustomAttribute(m_moduleBuilder, m_prToken.Token);
+ customBuilder.CreateCustomAttribute(m_moduleBuilder, m_tkProperty);
}
// Not supported functions in dynamic module.
public override Type? ReflectedType => m_containingType;
// These are package private so that TypeBuilder can access them.
- private string m_name; // The name of the property
- private PropertyToken m_prToken; // The token of this property
- private int m_tkProperty;
+ private string m_name; // The name of the property
+ private int m_tkProperty; // The token of this property
private ModuleBuilder m_moduleBuilder;
- private SignatureHelper m_signature;
- private PropertyAttributes m_attributes; // property's attribute flags
- private Type m_returnType; // property's return type
+ private PropertyAttributes m_attributes; // property's attribute flags
+ private Type m_returnType; // property's return type
private MethodInfo? m_getMethod;
private MethodInfo? m_setMethod;
private TypeBuilder m_containingType;
AddElementType(CorElementType.ELEMENT_TYPE_CMOD_OPT);
- int token = m_module!.GetTypeToken(t).Token;
+ int token = m_module!.GetTypeToken(t);
Debug.Assert(!MetadataToken.IsNullToken(token));
AddToken(token);
}
AddElementType(CorElementType.ELEMENT_TYPE_CMOD_REQD);
- int token = m_module!.GetTypeToken(t).Token;
+ int token = m_module!.GetTypeToken(t);
Debug.Assert(!MetadataToken.IsNullToken(token));
AddToken(token);
}
else if (clsArgument is TypeBuilder)
{
TypeBuilder clsBuilder = (TypeBuilder)clsArgument;
- TypeToken tkType;
+ int tkType;
if (clsBuilder.Module.Equals(m_module))
{
else if (clsArgument is EnumBuilder)
{
TypeBuilder clsBuilder = ((EnumBuilder)clsArgument).m_typeBuilder;
- TypeToken tkType;
+ int tkType;
if (clsBuilder.Module.Equals(m_module))
{
AddData(rid);
}
- private void InternalAddTypeToken(TypeToken clsToken, CorElementType CorType)
+ private void InternalAddTypeToken(int clsToken, CorElementType CorType)
{
// Add a type token into signature. CorType will be either CorElementType.ELEMENT_TYPE_CLASS or CorElementType.ELEMENT_TYPE_VALUETYPE
AddElementType(CorType);
- AddToken(clsToken.Token);
+ AddToken(clsToken);
}
private unsafe void InternalAddRuntimeType(Type type)
private string m_name;
private CallingConventions m_callingConvention;
private Type m_returnType;
- private MethodToken m_mdMethod;
+ private int m_token;
private Type[] m_parameterTypes;
- private SignatureHelper m_signature;
#endregion
#region Constructor
- internal SymbolMethod(ModuleBuilder mod, MethodToken token, Type arrayClass, string methodName,
+ internal SymbolMethod(ModuleBuilder mod, int token, Type arrayClass, string methodName,
CallingConventions callingConvention, Type? returnType, Type[]? parameterTypes)
{
// This is a kind of MethodInfo to represent methods for array type of unbaked type
// passed into it is this MethodToken. The MethodToken was forged using a TypeSpec for an Array type and
// the name of the method on Array.
// As none of the methods on Array have CustomModifiers their is no need to pass those around in here.
- m_mdMethod = token;
+ m_token = token;
// The ParameterTypes are also a bit interesting in that they may be unbaked TypeBuilders.
m_returnType = returnType ?? typeof(void);
m_name = methodName;
m_callingConvention = callingConvention;
- m_signature = SignatureHelper.GetMethodSigHelper(
+ // Validate signature
+ SignatureHelper.GetMethodSigHelper(
mod, callingConvention, returnType, null, null, parameterTypes, null, null);
}
#endregion
return m_parameterTypes;
}
- internal MethodToken GetToken(ModuleBuilder mod)
+ internal int GetToken(ModuleBuilder mod)
{
return mod.GetArrayMethodToken(m_containingType, m_name, m_callingConvention, m_returnType, m_parameterTypes);
}
return m_module;
}
- public MethodToken GetToken()
- {
- return m_mdMethod;
- }
-
#endregion
}
}
if (m_customBuilder == null)
{
Debug.Assert(m_con != null);
- DefineCustomAttribute(module, token, module.GetConstructorToken(m_con).Token,
+ DefineCustomAttribute(module, token, module.GetConstructorToken(m_con),
m_binaryAttribute, false, false);
}
else
#region Private Data Members
private List<CustAttr>? m_ca;
- private TypeToken m_tdType;
+ private int m_tdType;
private readonly ModuleBuilder m_module;
private readonly string? m_strName;
private readonly string? m_strNameSpace;
// ctor for the global (module) type
internal TypeBuilder(ModuleBuilder module)
{
- m_tdType = new TypeToken((int)MetadataTokenType.TypeDef);
+ m_tdType = ((int)MetadataTokenType.TypeDef);
m_isHiddenGlobalType = true;
m_module = module;
m_listMethods = new List<MethodBuilder>();
interfaceTokens = new int[interfaces.Length + 1];
for (i = 0; i < interfaces.Length; i++)
{
- interfaceTokens[i] = m_module.GetTypeTokenInternal(interfaces[i]).Token;
+ interfaceTokens[i] = m_module.GetTypeTokenInternal(interfaces[i]);
}
}
int tkParent = 0;
if (m_typeParent != null)
- tkParent = m_module.GetTypeTokenInternal(m_typeParent).Token;
+ tkParent = m_module.GetTypeTokenInternal(m_typeParent);
int tkEnclosingType = 0;
if (enclosingType != null)
{
- tkEnclosingType = enclosingType.m_tdType.Token;
+ tkEnclosingType = enclosingType.m_tdType;
}
- m_tdType = new TypeToken(DefineType(new QCallModule(ref module),
- fullname, tkParent, m_iAttr, tkEnclosingType, interfaceTokens!));
+ m_tdType = DefineType(new QCallModule(ref module),
+ fullname, tkParent, m_iAttr, tkEnclosingType, interfaceTokens!);
m_iPackingSize = iPackingSize;
m_iTypeSize = iTypeSize;
if ((m_iPackingSize != 0) || (m_iTypeSize != 0))
- SetClassLayout(new QCallModule(ref module), m_tdType.Token, m_iPackingSize, m_iTypeSize);
+ SetClassLayout(new QCallModule(ref module), m_tdType, m_iPackingSize, m_iTypeSize);
m_module.AddType(FullName!, this);
}
public override bool IsByRefLike => false;
- internal int MetadataTokenInternal => m_tdType.Token;
+ public override int MetadataToken => m_tdType;
#endregion
// Loader restriction: body method has to be from this class
throw new ArgumentException(SR.ArgumentException_BadMethodImplBody);
- MethodToken tkBody = m_module.GetMethodTokenInternal(methodInfoBody);
- MethodToken tkDecl = m_module.GetMethodTokenInternal(methodInfoDeclaration);
+ int tkBody = m_module.GetMethodToken(methodInfoBody);
+ int tkDecl = m_module.GetMethodToken(methodInfoDeclaration);
ModuleBuilder module = m_module;
- DefineMethodImpl(new QCallModule(ref module), m_tdType.Token, tkBody.Token, tkDecl.Token);
+ DefineMethodImpl(new QCallModule(ref module), m_tdType, tkBody, tkDecl);
}
public MethodBuilder DefineMethod(string name, MethodAttributes attributes, Type? returnType, Type[]? parameterTypes)
}
m_listMethods.Add(method);
- MethodToken token = method.GetToken();
+ int token = method.MetadataToken;
int linkFlags = 0;
switch (nativeCallConv)
SetPInvokeData(new QCallModule(ref module),
dllName,
importName,
- token.Token,
+ token,
linkFlags);
+
method.SetToken(token);
return method;
ModuleBuilder module = m_module;
- PropertyToken prToken = new PropertyToken(DefineProperty(
+ int prToken = DefineProperty(
new QCallModule(ref module),
- m_tdType.Token,
+ m_tdType,
name,
attributes,
sigBytes,
- sigLength));
+ sigLength);
// create the property builder now.
return new PropertyBuilder(
throw new ArgumentException(SR.Argument_IllegalName, nameof(name));
int tkType;
- EventToken evToken;
+ int evToken;
AssemblyBuilder.CheckContext(eventtype);
ThrowIfCreated();
- tkType = m_module.GetTypeTokenInternal(eventtype).Token;
+ tkType = m_module.GetTypeTokenInternal(eventtype);
// Internal helpers to define property records
ModuleBuilder module = m_module;
- evToken = new EventToken(DefineEvent(
+ evToken = DefineEvent(
new QCallModule(ref module),
- m_tdType.Token,
+ m_tdType,
name,
attributes,
- tkType));
+ tkType);
// create the property builder now.
return new EventBuilder(
int[] interfaceTokens = new int[m_typeInterfaces.Count];
for (int i = 0; i < m_typeInterfaces.Count; i++)
{
- interfaceTokens[i] = m_module.GetTypeTokenInternal(m_typeInterfaces[i]).Token;
+ interfaceTokens[i] = m_module.GetTypeTokenInternal(m_typeInterfaces[i]);
}
int tkParent = 0;
if (m_typeParent != null)
- tkParent = m_module.GetTypeTokenInternal(m_typeParent).Token;
+ tkParent = m_module.GetTypeTokenInternal(m_typeParent);
ModuleBuilder module = m_module;
for (int i = 0; i < m_typeInterfaces.Count; i++)
{
- constraints[i] = m_module.GetTypeTokenInternal(m_typeInterfaces[i]).Token;
+ constraints[i] = m_module.GetTypeTokenInternal(m_typeInterfaces[i]);
}
- int declMember = m_declMeth == null ? m_DeclaringType!.m_tdType.Token : m_declMeth.GetToken().Token;
- m_tdType = new TypeToken(DefineGenericParam(new QCallModule(ref module),
- m_strName!, declMember, m_genParamAttributes, m_genParamPos, constraints));
+ int declMember = m_declMeth == null ? m_DeclaringType!.m_tdType : m_declMeth.MetadataToken;
+ m_tdType = DefineGenericParam(new QCallModule(ref module),
+ m_strName!, declMember, m_genParamAttributes, m_genParamPos, constraints);
if (m_ca != null)
{
foreach (CustAttr ca in m_ca)
- ca.Bake(m_module, MetadataTokenInternal);
+ ca.Bake(m_module, MetadataToken);
}
m_hasBeenCreated = true;
else
{
// Check for global typebuilder
- if (((m_tdType.Token & 0x00FFFFFF) != 0) && ((tkParent & 0x00FFFFFF) != 0))
+ if (((m_tdType & 0x00FFFFFF) != 0) && ((tkParent & 0x00FFFFFF) != 0))
{
- SetParentType(new QCallModule(ref module), m_tdType.Token, tkParent);
+ SetParentType(new QCallModule(ref module), m_tdType, tkParent);
}
if (m_inst != null)
MethodBuilder meth = m_listMethods[i];
if (meth.IsGenericMethodDefinition)
- meth.GetToken(); // Doubles as "CreateMethod" for MethodBuilder -- analogous to CreateType()
+ {
+ int dummy = meth.MetadataToken; // Doubles as "CreateMethod" for MethodBuilder -- analogous to CreateType()
+ }
MethodAttributes methodAttrs = meth.Attributes;
ExceptionHandler[]? exceptions = meth.GetExceptionHandlers();
int[]? tokenFixups = meth.GetTokenFixups();
- SetMethodIL(new QCallModule(ref module), meth.GetToken().Token, meth.InitLocals,
+ SetMethodIL(new QCallModule(ref module), meth.MetadataToken, meth.InitLocals,
body, (body != null) ? body.Length : 0,
localSig, sigLength, maxStack,
exceptions, (exceptions != null) ? exceptions.Length : 0,
// Terminate the process.
RuntimeType? cls = null;
- TermCreateClass(new QCallModule(ref module), m_tdType.Token, ObjectHandleOnStack.Create(ref cls));
+ TermCreateClass(new QCallModule(ref module), m_tdType, ObjectHandleOnStack.Create(ref cls));
if (!m_isHiddenGlobalType)
{
ThrowIfCreated();
- TypeToken tkInterface = m_module.GetTypeTokenInternal(interfaceType);
+ int tkInterface = m_module.GetTypeTokenInternal(interfaceType);
ModuleBuilder module = m_module;
- AddInterfaceImpl(new QCallModule(ref module), m_tdType.Token, tkInterface.Token);
+ AddInterfaceImpl(new QCallModule(ref module), m_tdType, tkInterface);
m_typeInterfaces!.Add(interfaceType);
}
- public TypeToken TypeToken
+ internal int TypeToken
{
get
{
if (binaryAttribute == null)
throw new ArgumentNullException(nameof(binaryAttribute));
- DefineCustomAttribute(m_module, m_tdType.Token, ((ModuleBuilder)m_module).GetConstructorToken(con).Token,
+ DefineCustomAttribute(m_module, m_tdType, ((ModuleBuilder)m_module).GetConstructorToken(con),
binaryAttribute, false, false);
}
if (customBuilder == null)
throw new ArgumentNullException(nameof(customBuilder));
- customBuilder.CreateCustomAttribute((ModuleBuilder)m_module, m_tdType.Token);
+ customBuilder.CreateCustomAttribute((ModuleBuilder)m_module, m_tdType);
}
#endregion
public override object[] GetCustomAttributes(bool inherit) { return m_ctor.GetCustomAttributes(inherit); }
public override object[] GetCustomAttributes(Type attributeType, bool inherit) { return m_ctor.GetCustomAttributes(attributeType, inherit); }
public override bool IsDefined(Type attributeType, bool inherit) { return m_ctor.IsDefined(attributeType, inherit); }
- internal int MetadataTokenInternal
+ public override int MetadataToken
{
get
{
ConstructorBuilder? cb = m_ctor as ConstructorBuilder;
if (cb != null)
- return cb.MetadataTokenInternal;
+ return cb.MetadataToken;
else
{
Debug.Assert(m_ctor is RuntimeConstructorInfo);
public override object[] GetCustomAttributes(bool inherit) { return m_field.GetCustomAttributes(inherit); }
public override object[] GetCustomAttributes(Type attributeType, bool inherit) { return m_field.GetCustomAttributes(attributeType, inherit); }
public override bool IsDefined(Type attributeType, bool inherit) { return m_field.IsDefined(attributeType, inherit); }
- internal int MetadataTokenInternal
+ public override int MetadataToken
{
get
{
FieldBuilder? fb = m_field as FieldBuilder;
if (fb != null)
- return fb.MetadataTokenInternal;
+ return fb.MetadataToken;
else
{
Debug.Assert(m_field is RuntimeFieldInfo);
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\DefaultMemberAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\AssemblyBuilderAccess.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\EmptyCAHolder.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\EventToken.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\FieldToken.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\FlowControl.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\Label.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\MethodToken.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\Opcode.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\OpCodes.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\OpCodeType.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\OperandType.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\PackingSize.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\ParameterToken.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\PEFileKinds.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\PropertyToken.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\SignatureToken.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\StackBehaviour.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\StringToken.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\TypeNameBuilder.cs" />
- <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\Emit\TypeToken.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\EventAttributes.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\EventInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ExceptionHandlingClause.cs" />
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-namespace System.Reflection.Emit
-{
- public struct EventToken
- {
- public static readonly EventToken Empty;
-
- internal EventToken(int eventToken)
- {
- Token = eventToken;
- }
-
- public int Token { get; }
-
- public override int GetHashCode() => Token;
-
- public override bool Equals(object? obj) => obj is EventToken et && Equals(et);
-
- public bool Equals(EventToken obj) => obj.Token == Token;
-
- public static bool operator ==(EventToken a, EventToken b) => a.Equals(b);
-
- public static bool operator !=(EventToken a, EventToken b) => !(a == b);
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-namespace System.Reflection.Emit
-{
- /// <summary>
- /// The FieldToken class is an opaque representation of the Token returned
- /// by the Metadata to represent the field. FieldTokens are generated by
- /// Module.GetFieldToken(). There are no meaningful accessors on this class,
- /// but it can be passed to ILGenerator which understands it's internals.
- /// </summary>
- public struct FieldToken
- {
- public static readonly FieldToken Empty;
-
- private readonly object _class;
-
- internal FieldToken(int fieldToken, Type fieldClass)
- {
- Token = fieldToken;
- _class = fieldClass;
- }
-
- public int Token { get; }
-
- public override int GetHashCode() => Token;
-
- public override bool Equals(object? obj) => obj is FieldToken ft && Equals(ft);
-
- public bool Equals(FieldToken obj) => obj.Token == Token && obj._class == _class;
-
- public static bool operator ==(FieldToken a, FieldToken b) => a.Equals(b);
-
- public static bool operator !=(FieldToken a, FieldToken b) => !(a == b);
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-namespace System.Reflection.Emit
-{
- public struct MethodToken
- {
- public static readonly MethodToken Empty;
-
- internal MethodToken(int methodToken)
- {
- Token = methodToken;
- }
-
- public int Token { get; }
-
- public override int GetHashCode() => Token;
-
- public override bool Equals(object? obj) => obj is MethodToken mt && Equals(mt);
-
- public bool Equals(MethodToken obj) => obj.Token == Token;
-
- public static bool operator ==(MethodToken a, MethodToken b) => a.Equals(b);
-
- public static bool operator !=(MethodToken a, MethodToken b) => !(a == b);
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-namespace System.Reflection.Emit
-{
- /// <summary>
- /// The ParameterToken class is an opaque representation of the Token returned
- /// by the Metadata to represent the parameter.
- /// </summary>
- public struct ParameterToken
- {
- public static readonly ParameterToken Empty;
-
- internal ParameterToken(int parameterToken)
- {
- Token = parameterToken;
- }
-
- public int Token { get; }
-
- public override int GetHashCode() => Token;
-
- public override bool Equals(object? obj) => obj is ParameterToken pt && Equals(pt);
-
- public bool Equals(ParameterToken obj) => obj.Token == Token;
-
- public static bool operator ==(ParameterToken a, ParameterToken b) => a.Equals(b);
-
- public static bool operator !=(ParameterToken a, ParameterToken b) => !(a == b);
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-namespace System.Reflection.Emit
-{
- public struct PropertyToken
- {
- public static readonly PropertyToken Empty;
-
- internal PropertyToken(int propertyToken)
- {
- Token = propertyToken;
- }
-
- public int Token { get; }
-
- public override int GetHashCode() => Token;
-
- public override bool Equals(object? obj) => obj is PropertyToken pt && Equals(pt);
-
- public bool Equals(PropertyToken obj) => obj.Token == Token;
-
- public static bool operator ==(PropertyToken a, PropertyToken b) => a.Equals(b);
-
- public static bool operator !=(PropertyToken a, PropertyToken b) => !(a == b);
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-namespace System.Reflection.Emit
-{
- public struct SignatureToken
- {
- public static readonly SignatureToken Empty;
-
- internal SignatureToken(int signatureToken)
- {
- Token = signatureToken;
- }
-
- public int Token { get; }
-
- public override int GetHashCode() => Token;
-
- public override bool Equals(object? obj) => obj is SignatureToken st && Equals(st);
-
- public bool Equals(SignatureToken obj) => obj.Token == Token;
-
- public static bool operator ==(SignatureToken a, SignatureToken b) => a.Equals(b);
-
- public static bool operator !=(SignatureToken a, SignatureToken b) => !(a == b);
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-namespace System.Reflection.Emit
-{
- public struct StringToken
- {
- internal StringToken(int str)
- {
- Token = str;
- }
-
- // Returns the metadata token for this particular string.
- // Generated by a call to Module.GetStringConstant().
- //
- public int Token { get; }
-
- public override int GetHashCode() => Token;
-
- public override bool Equals(object? obj) => obj is StringToken st && Equals(st);
-
- public bool Equals(StringToken obj) => obj.Token == Token;
-
- public static bool operator ==(StringToken a, StringToken b) => a.Equals(b);
-
- public static bool operator !=(StringToken a, StringToken b) => !(a == b);
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-namespace System.Reflection.Emit
-{
- public struct TypeToken
- {
- public static readonly TypeToken Empty;
-
- internal TypeToken(int typeToken)
- {
- Token = typeToken;
- }
-
- public int Token { get; }
-
- public override int GetHashCode() => Token;
-
- public override bool Equals(object? obj) => obj is TypeToken tt && Equals(tt);
-
- public bool Equals(TypeToken obj) => obj.Token == Token;
-
- public static bool operator ==(TypeToken a, TypeToken b) => a.Equals(b);
-
- public static bool operator !=(TypeToken a, TypeToken b) => !(a == b);
- }
-}
MembersMustExist : Member 'public void System.Reflection.Emit.ILGenerator.MarkSequencePoint(System.Diagnostics.SymbolStore.ISymbolDocumentWriter, System.Int32, System.Int32, System.Int32, System.Int32)' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'public void System.Reflection.Emit.LocalBuilder.SetLocalSymInfo(System.String)' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'public void System.Reflection.Emit.LocalBuilder.SetLocalSymInfo(System.String, System.Int32, System.Int32)' does not exist in the reference but it does exist in the implementation.
-MembersMustExist : Member 'public System.Reflection.Emit.ParameterToken System.Reflection.Emit.ParameterBuilder.GetToken()' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'public System.Reflection.Emit.SignatureHelper System.Reflection.Emit.SignatureHelper.GetMethodSigHelper(System.Reflection.Module, System.Runtime.InteropServices.CallingConvention, System.Type)' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'public System.Reflection.Emit.SignatureHelper System.Reflection.Emit.SignatureHelper.GetMethodSigHelper(System.Runtime.InteropServices.CallingConvention, System.Type)' does not exist in the reference but it does exist in the implementation.
-Total Issues: 6
+Total Issues: 5
public override object Invoke(object? obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder? binder, object?[]? parameters, System.Globalization.CultureInfo? culture) { throw null; }
public override object Invoke(System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder? binder, object?[]? parameters, System.Globalization.CultureInfo? culture) { throw null; }
public override bool IsDefined(System.Type attributeType, bool inherit) { throw null; }
+ public override int MetadataToken { get { throw null; } }
public void SetCustomAttribute(System.Reflection.ConstructorInfo con, byte[] binaryAttribute) { }
public void SetCustomAttribute(System.Reflection.Emit.CustomAttributeBuilder customBuilder) { }
public void SetImplementationFlags(System.Reflection.MethodImplAttributes attributes) { }
public override System.Type? DeclaringType { get { throw null; } }
public override System.RuntimeFieldHandle FieldHandle { get { throw null; } }
public override System.Type FieldType { get { throw null; } }
+ public override int MetadataToken { get { throw null; } }
public override System.Reflection.Module Module { get { throw null; } }
public override string Name { get { throw null; } }
public override System.Type? ReflectedType { get { throw null; } }
public override bool IsSZArray { get { throw null; } }
public override bool IsTypeDefinition { get { throw null; } }
public override bool IsVariableBoundArray { get { throw null; } }
+ public override int MetadataToken { get { throw null; } }
public override System.Reflection.Module Module { get { throw null; } }
public override string Name { get { throw null; } }
public override string? Namespace { get { throw null; } }
public override bool IsSecurityCritical { get { throw null; } }
public override bool IsSecuritySafeCritical { get { throw null; } }
public override bool IsSecurityTransparent { get { throw null; } }
+ public override int MetadataToken { get { throw null; } }
public override System.RuntimeMethodHandle MethodHandle { get { throw null; } }
public override System.Reflection.Module Module { get { throw null; } }
public override string Name { get { throw null; } }
public override bool IsSZArray { get { throw null; } }
public override bool IsTypeDefinition { get { throw null; } }
public override bool IsVariableBoundArray { get { throw null; } }
+ public override int MetadataToken { get { throw null; } }
public override System.Reflection.Module Module { get { throw null; } }
public override string Name { get { throw null; } }
public override string? Namespace { get { throw null; } }
Compat issues with assembly System.Reflection.Emit:
MembersMustExist : Member 'public System.Reflection.Emit.ModuleBuilder System.Reflection.Emit.AssemblyBuilder.DefineDynamicModule(System.String, System.Boolean)' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'public System.Reflection.Module System.Reflection.Emit.ConstructorBuilder.GetModule()' does not exist in the reference but it does exist in the implementation.
-MembersMustExist : Member 'public System.Reflection.Emit.MethodToken System.Reflection.Emit.ConstructorBuilder.GetToken()' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'public System.String System.Reflection.Emit.ConstructorBuilder.Signature.get()' does not exist in the reference but it does exist in the implementation.
CannotRemoveBaseTypeOrInterface : Type 'System.Reflection.Emit.EnumBuilder' does not inherit from base type 'System.Reflection.TypeInfo' in the reference but it does in the implementation.
MembersMustExist : Member 'public System.Type System.Reflection.Emit.EnumBuilder.CreateType()' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'public System.Boolean System.Reflection.Emit.EnumBuilder.IsAssignableFrom(System.Reflection.TypeInfo)' does not exist in the reference but it does exist in the implementation.
-MembersMustExist : Member 'public System.Reflection.Emit.TypeToken System.Reflection.Emit.EnumBuilder.TypeToken.get()' does not exist in the reference but it does exist in the implementation.
-MembersMustExist : Member 'public System.Reflection.Emit.EventToken System.Reflection.Emit.EventBuilder.GetEventToken()' does not exist in the reference but it does exist in the implementation.
-MembersMustExist : Member 'public System.Reflection.Emit.FieldToken System.Reflection.Emit.FieldBuilder.GetToken()' does not exist in the reference but it does exist in the implementation.
CannotRemoveBaseTypeOrInterface : Type 'System.Reflection.Emit.GenericTypeParameterBuilder' does not inherit from base type 'System.Reflection.TypeInfo' in the reference but it does in the implementation.
MembersMustExist : Member 'public System.Boolean System.Reflection.Emit.GenericTypeParameterBuilder.IsAssignableFrom(System.Reflection.TypeInfo)' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'public System.Reflection.Module System.Reflection.Emit.MethodBuilder.GetModule()' does not exist in the reference but it does exist in the implementation.
-MembersMustExist : Member 'public System.Reflection.Emit.MethodToken System.Reflection.Emit.MethodBuilder.GetToken()' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'public System.String System.Reflection.Emit.MethodBuilder.Signature.get()' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'public System.Diagnostics.SymbolStore.ISymbolDocumentWriter System.Reflection.Emit.ModuleBuilder.DefineDocument(System.String, System.Guid, System.Guid, System.Guid)' does not exist in the reference but it does exist in the implementation.
-MembersMustExist : Member 'public System.Reflection.Emit.MethodToken System.Reflection.Emit.ModuleBuilder.GetArrayMethodToken(System.Type, System.String, System.Reflection.CallingConventions, System.Type, System.Type[])' does not exist in the reference but it does exist in the implementation.
-MembersMustExist : Member 'public System.Reflection.Emit.MethodToken System.Reflection.Emit.ModuleBuilder.GetConstructorToken(System.Reflection.ConstructorInfo)' does not exist in the reference but it does exist in the implementation.
-MembersMustExist : Member 'public System.Reflection.Emit.FieldToken System.Reflection.Emit.ModuleBuilder.GetFieldToken(System.Reflection.FieldInfo)' does not exist in the reference but it does exist in the implementation.
-MembersMustExist : Member 'public System.Reflection.Emit.MethodToken System.Reflection.Emit.ModuleBuilder.GetMethodToken(System.Reflection.MethodInfo)' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'protected System.ModuleHandle System.Reflection.Emit.ModuleBuilder.GetModuleHandleImpl()' does not exist in the reference but it does exist in the implementation.
-MembersMustExist : Member 'public System.Reflection.Emit.SignatureToken System.Reflection.Emit.ModuleBuilder.GetSignatureToken(System.Byte[], System.Int32)' does not exist in the reference but it does exist in the implementation.
-MembersMustExist : Member 'public System.Reflection.Emit.SignatureToken System.Reflection.Emit.ModuleBuilder.GetSignatureToken(System.Reflection.Emit.SignatureHelper)' does not exist in the reference but it does exist in the implementation.
-MembersMustExist : Member 'public System.Reflection.Emit.StringToken System.Reflection.Emit.ModuleBuilder.GetStringConstant(System.String)' does not exist in the reference but it does exist in the implementation.
-MembersMustExist : Member 'public System.Reflection.Emit.TypeToken System.Reflection.Emit.ModuleBuilder.GetTypeToken(System.String)' does not exist in the reference but it does exist in the implementation.
-MembersMustExist : Member 'public System.Reflection.Emit.TypeToken System.Reflection.Emit.ModuleBuilder.GetTypeToken(System.Type)' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'public System.Boolean System.Reflection.Emit.ModuleBuilder.IsTransient()' does not exist in the reference but it does exist in the implementation.
-MembersMustExist : Member 'public System.Reflection.Emit.PropertyToken System.Reflection.Emit.PropertyBuilder.PropertyToken.get()' does not exist in the reference but it does exist in the implementation.
CannotRemoveBaseTypeOrInterface : Type 'System.Reflection.Emit.TypeBuilder' does not inherit from base type 'System.Reflection.TypeInfo' in the reference but it does in the implementation.
MembersMustExist : Member 'public System.Boolean System.Reflection.Emit.TypeBuilder.IsAssignableFrom(System.Reflection.TypeInfo)' does not exist in the reference but it does exist in the implementation.
-MembersMustExist : Member 'public System.Reflection.Emit.TypeToken System.Reflection.Emit.TypeBuilder.TypeToken.get()' does not exist in the reference but it does exist in the implementation.
-Total Issues: 31
+Total Issues: 15
// Invoke the method to verify it works correctly
MethodInfo resultMethod = resultType.GetMethod("TestMethod");
Assert.Equal(expectedReturn, resultMethod.Invoke(null, new object[] { "hello", new object() }));
+
+ // Verify MetadataToken
+ Assert.Equal(method.MetadataToken, resultMethod.MetadataToken);
+ MethodInfo methodFromToken = (MethodInfo)type.Module.ResolveMethod(method.MetadataToken);
+ Assert.Equal(resultMethod, methodFromToken);
}
[Fact]
ilGenerator.Emit(OpCodes.Ret);
Type createdType = type.CreateTypeInfo().AsType();
- MethodInfo createedMethod = createdType.GetMethod("TestMethod");
- Assert.Equal(expectedReturn, createedMethod.Invoke(null, null));
+ MethodInfo createdMethod = createdType.GetMethod("TestMethod");
+ Assert.Equal(expectedReturn, createdMethod.Invoke(null, null));
+
+ // Verify MetadataToken
+ Assert.Equal(method.MetadataToken, createdMethod.MetadataToken);
+ MethodInfo methodFromToken = (MethodInfo)type.Module.ResolveMethod(method.MetadataToken);
+ Assert.Equal(createdMethod, methodFromToken);
+
+ MemberInfo memberInfoFromToken = (MemberInfo)type.Module.ResolveMember(method.MetadataToken);
+ Assert.Equal(methodFromToken, memberInfoFromToken);
}
[Theory]
Type createdType = type.CreateType();
Assert.Equal(type.Name, createdType.Name);
- Assert.Equal(type.CreateTypeInfo(), createdType.GetTypeInfo());
+ TypeInfo typeInfo = type.CreateTypeInfo();
+ Assert.Equal(typeInfo, createdType.GetTypeInfo());
+
+ // Verify MetadataToken
+ Assert.Equal(type.MetadataToken, typeInfo.MetadataToken);
+ TypeInfo typeFromToken = (TypeInfo)type.Module.ResolveType(typeInfo.MetadataToken);
+ Assert.Equal(createdType, typeFromToken);
}
[Theory]
Type createdType = type.CreateTypeInfo().AsType();
Assert.Equal(type.AsType().GetFields(Helpers.AllFlags), createdType.GetFields(Helpers.AllFlags));
- Assert.Equal(type.AsType().GetField(name, Helpers.AllFlags), createdType.GetField(name, Helpers.AllFlags));
+
+ FieldInfo fieldInfo = createdType.GetField(name, Helpers.AllFlags);
+ Assert.Equal(type.AsType().GetField(name, Helpers.AllFlags), fieldInfo);
+
+ if (fieldInfo != null)
+ {
+ // Verify MetadataToken
+ Assert.Equal(field.MetadataToken, fieldInfo.MetadataToken);
+ FieldInfo fieldFromToken = (FieldInfo)fieldInfo.Module.ResolveField(fieldInfo.MetadataToken);
+ Assert.Equal(fieldInfo, fieldFromToken);
+ }
}
[Fact]
}
[ConditionalFact(nameof(GetMetadataTokenSupported), nameof(IsReflectionEmitSupported))]
- public static void UnbakedReflectionEmitType_HasNoMetadataToken()
+ public static void ReflectionEmitType_HasMetadataToken()
{
AssemblyBuilder assembly = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("dynamic"), AssemblyBuilderAccess.Run);
ModuleBuilder module = assembly.DefineDynamicModule("dynamic.dll");
TypeBuilder type = module.DefineType("T");
MethodInfo method = type.DefineMethod("M", MethodAttributes.Public);
- Assert.False(method.HasMetadataToken());
- Assert.Throws<InvalidOperationException>(() => method.GetMetadataToken());
+
+ Assert.True(method.HasMetadataToken());
+ Assert.NotEqual(0, method.GetMetadataToken());
}
public static bool GetMetadataTokenSupported => true;
this.paramModOpt = paramModOpt;
table_idx = get_next_table_index(this, 0x06, 1);
- ((ModuleBuilder)tb.Module).RegisterToken(this, GetToken().Token);
+ ((ModuleBuilder)tb.Module).RegisterToken(this, MetadataToken);
}
// FIXME:
throw not_supported();
}
+ public override int MetadataToken => 0x06000000 | table_idx;
+
public override RuntimeMethodHandle MethodHandle
{
get
return type.Module;
}
- public MethodToken GetToken()
- {
- return new MethodToken(0x06000000 | table_idx);
- }
-
public override Module Module
{
get
}
}
- public TypeToken TypeToken
+ internal int TypeToken
{
get
{
- return _tb.TypeToken;
+ return _tb.MetadataToken;
}
}
other_methods[other_methods.Length - 1] = mdBuilder;
}
- public EventToken GetEventToken()
- {
- return new EventToken(0x14000000 | table_idx);
- }
public void SetAddOnMethod(MethodBuilder mdBuilder)
{
if (mdBuilder == null)
offset = -1;
typeb = tb;
- ((ModuleBuilder)tb.Module).RegisterToken(this, GetToken().Token);
+ ((ModuleBuilder)tb.Module).RegisterToken(this, MetadataToken);
}
public override FieldAttributes Attributes
public override int MetadataToken { get { return ((ModuleBuilder)typeb.Module).GetToken(this); } }
- public FieldToken GetToken()
- {
- return new FieldToken(MetadataToken, type);
- }
-
public override object? GetValue(object? obj)
{
throw CreateNotSupportedException();
type = tb;
table_idx = get_next_table_index(this, 0x06, 1);
- ((ModuleBuilder)tb.Module).RegisterToken(this, GetToken().Token);
+ ((ModuleBuilder)tb.Module).RegisterToken(this, MetadataToken);
}
internal MethodBuilder(TypeBuilder tb, string name, MethodAttributes attributes,
get { return type; }
}
+ public override int MetadataToken => 0x06000000 | table_idx;
+
public override RuntimeMethodHandle MethodHandle
{
get
}
}
- public MethodToken GetToken()
- {
- return new MethodToken(0x06000000 | table_idx);
- }
-
public override MethodInfo GetBaseDefinition()
{
return this;
return copy;
}
- public MethodToken GetMethodToken(MethodInfo method)
+ internal int GetMethodToken(MethodInfo method)
{
if (method == null)
throw new ArgumentNullException(nameof(method));
- return new MethodToken(GetToken(method));
+ return method.MetadataToken;
}
- public MethodToken GetArrayMethodToken(Type arrayClass, string methodName, CallingConventions callingConvention, Type? returnType, Type[]? parameterTypes)
+ internal int GetArrayMethodToken(Type arrayClass, string methodName, CallingConventions callingConvention, Type? returnType, Type[]? parameterTypes)
{
return GetMethodToken(GetArrayMethod(arrayClass, methodName, callingConvention, returnType, parameterTypes));
}
[ComVisible(true)]
- public MethodToken GetConstructorToken(ConstructorInfo con)
+ internal int GetConstructorToken(ConstructorInfo con)
{
if (con == null)
throw new ArgumentNullException(nameof(con));
- return new MethodToken(GetToken(con));
+ return con.MetadataToken;
}
- public FieldToken GetFieldToken(FieldInfo field)
+ internal int GetFieldToken(FieldInfo field)
{
if (field == null)
throw new ArgumentNullException(nameof(field));
- return new FieldToken(GetToken (field), field.GetType());
+ return field.MetadataToken;
}
// FIXME:
- public SignatureToken GetSignatureToken(byte[] sigBytes, int sigLength)
+ internal int GetSignatureToken(byte[] sigBytes, int sigLength)
{
throw new NotImplementedException();
}
- public SignatureToken GetSignatureToken(SignatureHelper sigHelper)
+ internal int GetSignatureToken(SignatureHelper sigHelper)
{
if (sigHelper == null)
throw new ArgumentNullException(nameof(sigHelper));
- return new SignatureToken(GetToken(sigHelper));
+ return GetToken(sigHelper);
}
- public StringToken GetStringConstant(string str)
+ internal int GetStringConstant(string str)
{
if (str == null)
throw new ArgumentNullException(nameof(str));
- return new StringToken(GetToken(str));
+ return GetToken(str);
}
- public TypeToken GetTypeToken(Type type)
+ internal int GetTypeToken(Type type)
{
if (type == null)
throw new ArgumentNullException(nameof(type));
throw new ArgumentException("type can't be a byref type", nameof(type));
if (!IsTransient() && (type.Module is ModuleBuilder) && ((ModuleBuilder)type.Module).IsTransient())
throw new InvalidOperationException("a non-transient module can't reference a transient module");
- return new TypeToken(GetToken(type));
+ return type.MetadataToken;
}
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
Justification = "Reflection.Emit is not subject to trimming")]
- public TypeToken GetTypeToken(string name)
+ internal int GetTypeToken(string name)
{
return GetTypeToken(GetType(name)!);
}
get { return position; }
}
- public virtual ParameterToken GetToken()
- {
- return new ParameterToken(0x08 | table_idx);
- }
-
public virtual void SetConstant(object? defaultValue)
{
if (position > 0)
{
get { return name; }
}
- public PropertyToken PropertyToken
- {
- get { return default; }
- }
public override Type PropertyType
{
get { return type; }
return DefineField(name, datablobtype, attributes | FieldAttributes.Static | FieldAttributes.HasFieldRVA);
}
- public TypeToken TypeToken
- {
- get
- {
- return new TypeToken(0x02000000 | table_idx);
- }
- }
+ public override int MetadataToken => 0x02000000 | table_idx;
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2074:UnrecognizedReflectionPattern",
Justification = "Linker doesn't recongnize ResolveUserType")]