public MethodToken GetToken() { if (this.m_tkMethod.Token != 0) { return(this.m_tkMethod); } MethodBuilder builder = null; MethodToken tokenNoLock = new MethodToken(0); lock (this.m_containingType.m_listMethods) { if (this.m_tkMethod.Token != 0) { return(this.m_tkMethod); } int num = this.m_containingType.m_lastTokenizedMethod + 1; while (num < this.m_containingType.m_listMethods.Count) { builder = this.m_containingType.m_listMethods[num]; tokenNoLock = builder.GetTokenNoLock(); if (builder == this) { break; } num++; } this.m_containingType.m_lastTokenizedMethod = num; } return(tokenNoLock); }
public MethodToken GetToken() { if (m_tkMethod.Token == 0) { if (m_link != null) { m_link.GetToken(); } int sigLength; byte[] sigBytes = GetMethodSignature().InternalGetSignature(out sigLength); m_tkMethod = new MethodToken(TypeBuilder.InternalDefineMethod( m_containingType.MetadataTokenInternal, m_strName, sigBytes, sigLength, Attributes, m_module)); if (m_inst != null) { foreach (GenericTypeParameterBuilder tb in m_inst) { if (!tb.m_type.IsCreated()) { tb.m_type.CreateType(); } } } TypeBuilder.InternalSetMethodImpl(m_module, MetadataTokenInternal, m_dwMethodImplFlags); } return(m_tkMethod); }
//*********************************************** // // Constructor // //*********************************************** internal SymbolMethod( ModuleBuilder mod, MethodToken token, Type arrayClass, String methodName, CallingConventions callingConvention, Type returnType, Type[] parameterTypes) { m_module = mod; m_containingType = arrayClass; m_name = methodName; m_callingConvention = callingConvention; m_returnType = returnType; m_mdMethod = token; if (parameterTypes != null) { m_parameterTypes = new Type[parameterTypes.Length]; Array.Copy(parameterTypes, m_parameterTypes, parameterTypes.Length); } else m_parameterTypes = null; m_signature = SignatureHelper.GetMethodSigHelper(mod, callingConvention, returnType, parameterTypes); }
internal SymbolMethod(ModuleBuilder mod, MethodToken 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 // Another way to look at this class is as a glorified MethodToken wrapper. At the time of this comment // this class is only constructed inside ModuleBuilder.GetArrayMethod and the only interesting thing // 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; // The ParameterTypes are also a bit interesting in that they may be unbaked TypeBuilders. m_returnType = returnType; if (parameterTypes != null) { m_parameterTypes = new Type[parameterTypes.Length]; Array.Copy(parameterTypes, 0, m_parameterTypes, 0, parameterTypes.Length); } else { m_parameterTypes = EmptyArray<Type>.Value; } m_module = mod; m_containingType = arrayClass; m_name = methodName; m_callingConvention = callingConvention; m_signature = SignatureHelper.GetMethodSigHelper( mod, callingConvention, returnType, null, null, parameterTypes, null, null); }
private MethodToken GetTokenNoLock() { Debug.Assert(m_tkMethod.Token == 0, "m_tkMethod should not have been initialized"); int sigLength; byte[] sigBytes = GetMethodSignature().InternalGetSignature(out sigLength); int token = TypeBuilder.DefineMethod(m_module.GetNativeHandle(), m_containingType.MetadataTokenInternal, m_strName, sigBytes, sigLength, Attributes); m_tkMethod = new MethodToken(token); if (m_inst != null) { foreach (GenericTypeParameterBuilder tb in m_inst) { if (!tb.m_type.IsCreated()) { tb.m_type.CreateType(); } } } TypeBuilder.SetMethodImpl(m_module.GetNativeHandle(), token, m_dwMethodImplFlags); return(m_tkMethod); }
internal SymbolMethod(ModuleBuilder mod, MethodToken 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 // Another way to look at this class is as a glorified MethodToken wrapper. At the time of this comment // this class is only constructed inside ModuleBuilder.GetArrayMethod and the only interesting thing // 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; // The ParameterTypes are also a bit interesting in that they may be unbaked TypeBuilders. m_returnType = returnType; if (parameterTypes != null) { m_parameterTypes = new Type[parameterTypes.Length]; Array.Copy(parameterTypes, 0, m_parameterTypes, 0, parameterTypes.Length); } else { m_parameterTypes = EmptyArray <Type> .Value; } m_module = mod; m_containingType = arrayClass; m_name = methodName; m_callingConvention = callingConvention; m_signature = SignatureHelper.GetMethodSigHelper( mod, callingConvention, returnType, null, null, parameterTypes, null, null); }
//*********************************************** // // Constructor // //*********************************************** internal SymbolMethod( ModuleBuilder mod, MethodToken token, Type arrayClass, String methodName, CallingConventions callingConvention, Type returnType, Type[] parameterTypes) { m_module = mod; m_containingType = arrayClass; m_name = methodName; m_callingConvention = callingConvention; m_returnType = returnType; m_mdMethod = token; if (parameterTypes != null) { m_parameterTypes = new Type[parameterTypes.Length]; Array.Copy(parameterTypes, m_parameterTypes, parameterTypes.Length); } else { m_parameterTypes = null; } m_signature = SignatureHelper.GetMethodSigHelper(mod, callingConvention, returnType, parameterTypes); }
internal ConstructorBuilder(string name, MethodAttributes attributes, CallingConventions callingConvention, Type[] parameterTypes, Type[][] requiredCustomModifiers, Type[][] optionalCustomModifiers, ModuleBuilder mod, TypeBuilder type) { this.m_methodBuilder = new MethodBuilder(name, attributes, callingConvention, null, null, null, parameterTypes, requiredCustomModifiers, optionalCustomModifiers, mod, type, false); type.m_listMethods.Add(this.m_methodBuilder); int num; byte[] array = this.m_methodBuilder.GetMethodSignature().InternalGetSignature(out num); MethodToken token = this.m_methodBuilder.GetToken(); }
internal static SignatureHelper GetMethodSigHelper (Module mod, MethodToken token) { lock (typeof(AssemblyBuilder)) { IntPtr context = ModuleToContext(mod); IntPtr sig = ClrSigCreateMethodCopy (context, mod.privateData, token.Token); return(new SignatureHelper(mod, context, sig)); } }
/// <summary>Tests whether the given object is equal to this MethodToken object.</summary> /// <returns>true if <paramref name="obj" /> is an instance of MethodToken and is equal to this object; otherwise, false.</returns> /// <param name="obj">The object to compare to this object. </param> public override bool Equals(object obj) { bool flag = obj is MethodToken; if (flag) { MethodToken methodToken = (MethodToken)obj; flag = (this.tokValue == methodToken.tokValue); } return(flag); }
/// <summary> /// </summary> public override bool Equals(object obj) { bool res = obj is MethodToken; if (res) { MethodToken that = (MethodToken)obj; res = (this.tokValue == that.tokValue); } return(res); }
public MethodToken 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 // didn't change: the same order the MethodBuilders are constructed. The recursion introduced // will overflow the stack when there are many methods on the same type (10000 in my experiment). // The change also introduced race conditions. Before the code change GetToken is called from // the MethodBuilder .ctor which is protected by lock(ModuleBuilder.SyncRoot). Now it // could be called more than once on the the same method introducing duplicate (invalid) tokens. // 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) { return(m_tkMethod); } MethodBuilder?currentMethod = null; MethodToken currentToken = new MethodToken(0); int i; // We need to lock here to prevent a method from being "tokenized" twice. // We don't need to synchronize this with Type.DefineMethod because it only appends newly // constructed MethodBuilders to the end of m_listMethods lock (m_containingType.m_listMethods) { if (m_tkMethod.Token != 0) { return(m_tkMethod); } // If m_tkMethod is still 0 when we obtain the lock, m_lastTokenizedMethod must be smaller // than the index of the current method. for (i = m_containingType.m_lastTokenizedMethod + 1; i < m_containingType.m_listMethods.Count; ++i) { currentMethod = m_containingType.m_listMethods[i]; currentToken = currentMethod.GetTokenNoLock(); if (currentMethod == this) { break; } } m_containingType.m_lastTokenizedMethod = i; } 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"); return(currentToken); }
internal SymbolMethod(ModuleBuilder mod, MethodToken token, Type arrayClass, string methodName, CallingConventions callingConvention, Type returnType, Type[] parameterTypes) { this.m_mdMethod = token; this.m_returnType = returnType; if (parameterTypes != null) { this.m_parameterTypes = new Type[parameterTypes.Length]; Array.Copy((Array)parameterTypes, (Array)this.m_parameterTypes, parameterTypes.Length); } else { this.m_parameterTypes = EmptyArray <Type> .Value; } this.m_module = mod; this.m_containingType = arrayClass; this.m_name = methodName; this.m_callingConvention = callingConvention; this.m_signature = SignatureHelper.GetMethodSigHelper((Module)mod, callingConvention, returnType, (Type[])null, (Type[])null, parameterTypes, (Type[][])null, (Type[][])null); }
private MethodToken GetTokenNoLock() { int num; byte[] signature = this.GetMethodSignature().InternalGetSignature(out num); int str = TypeBuilder.DefineMethod(this.m_module.GetNativeHandle(), this.m_containingType.MetadataTokenInternal, this.m_strName, signature, num, this.Attributes); this.m_tkMethod = new MethodToken(str); if (this.m_inst != null) { foreach (GenericTypeParameterBuilder builder in this.m_inst) { if (!builder.m_type.IsCreated()) { builder.m_type.CreateType(); } } } TypeBuilder.SetMethodImpl(this.m_module.GetNativeHandle(), str, this.m_dwMethodImplFlags); return(this.m_tkMethod); }
// Define a method override declaration for this class. public void DefineMethodOverride (MethodInfo methodInfoBody, MethodInfo methodInfoDeclaration) { try { StartSync(); // Validate the parameters. if (methodInfoBody == null) { throw new ArgumentNullException("methodInfoBody"); } if (methodInfoDeclaration == null) { throw new ArgumentNullException ("methodInfoDeclaration"); } if (methodInfoBody.DeclaringType != this) { throw new ArgumentException (_("Emit_OverrideBodyNotInType")); } MethodToken bodyToken = module.GetMethodToken (methodInfoBody); MethodToken declToken = module.GetMethodToken (methodInfoDeclaration); lock (typeof(AssemblyBuilder)) { ClrTypeAddOverride (module.privateData, bodyToken.Token, declToken.Token); } } finally { EndSync(); } }
extern private static void ClrPropertyAddSemantics (IntPtr item, MethodSemanticsAttributes attr, MethodToken token);
// Summary: // Indicates whether the current instance is equal to the specified System.Reflection.Emit.MethodToken. // // Parameters: // obj: // The System.Reflection.Emit.MethodToken to compare to the current instance. // // Returns: // true if the value of obj is equal to the value of the current instance; otherwise, // false. extern public bool Equals(MethodToken obj);
public bool Equals (MethodToken obj) { return (this.tokValue == obj.tokValue); }
[System.Security.SecuritySafeCritical] // auto-generated public MethodToken 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 // didn't change: the same order the MethodBuilders are constructed. The recursion introduced // will overflow the stack when there are many methods on the same type (10000 in my experiment). // The change also introduced race conditions. Before the code change GetToken is called from // the MethodBuilder .ctor which is protected by lock(ModuleBuilder.SyncRoot). Now it // could be called more than once on the the same method introducing duplicate (invalid) tokens. // 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) { return m_tkMethod; } MethodBuilder currentMethod = null; MethodToken currentToken = new MethodToken(0); int i; // We need to lock here to prevent a method from being "tokenized" twice. // We don't need to synchronize this with Type.DefineMethod because it only appends newly // constructed MethodBuilders to the end of m_listMethods lock (m_containingType.m_listMethods) { if (m_tkMethod.Token != 0) { return m_tkMethod; } // If m_tkMethod is still 0 when we obtain the lock, m_lastTokenizedMethod must be smaller // than the index of the current method. for (i = m_containingType.m_lastTokenizedMethod + 1; i < m_containingType.m_listMethods.Count; ++i) { currentMethod = m_containingType.m_listMethods[i]; currentToken = currentMethod.GetTokenNoLock(); if (currentMethod == this) break; } m_containingType.m_lastTokenizedMethod = i; } Contract.Assert(currentMethod == this, "We should have found this method in m_containingType.m_listMethods"); Contract.Assert(currentToken.Token != 0, "The token should not be 0"); return currentToken; }
public bool Equals(MethodToken obj) { return(obj.m_method == m_method); }
internal void SetToken(MethodToken token) { m_tkMethod = token; }
extern private static void ClrEventAddSemantics (IntPtr eventInfo, MethodSemanticsAttributes attr, MethodToken token);
public bool Equals(MethodToken obj) { return(default(bool)); }
public MethodToken GetToken() { if (this.m_tkMethod.Token != 0) { return this.m_tkMethod; } MethodBuilder builder = null; MethodToken tokenNoLock = new MethodToken(0); lock (this.m_containingType.m_listMethods) { if (this.m_tkMethod.Token != 0) { return this.m_tkMethod; } int num = this.m_containingType.m_lastTokenizedMethod + 1; while (num < this.m_containingType.m_listMethods.Count) { builder = this.m_containingType.m_listMethods[num]; tokenNoLock = builder.GetTokenNoLock(); if (builder == this) { break; } num++; } this.m_containingType.m_lastTokenizedMethod = num; } return tokenNoLock; }
/********************************************** * Set the token within the context of the defining TypeBuilder. * @param token The token within the containing TypeBuilder. **********************************************/ internal void SetToken(MethodToken token) { m_mdMethod = token; }
internal void SetEntryPoint(MethodToken entryPoint) { this.m_EntryPoint = entryPoint; }
private MethodToken GetTokenNoLock() { int num; byte[] signature = this.GetMethodSignature().InternalGetSignature(out num); int str = TypeBuilder.DefineMethod(this.m_module.GetNativeHandle(), this.m_containingType.MetadataTokenInternal, this.m_strName, signature, num, this.Attributes); this.m_tkMethod = new MethodToken(str); if (this.m_inst != null) { foreach (GenericTypeParameterBuilder builder in this.m_inst) { if (!builder.m_type.IsCreated()) { builder.m_type.CreateType(); } } } TypeBuilder.SetMethodImpl(this.m_module.GetNativeHandle(), str, this.m_dwMethodImplFlags); return this.m_tkMethod; }
internal void SetToken(MethodToken token) { this.m_tkMethod = token; }
public bool Equals(MethodToken obj) { return obj.m_method == m_method; }
static MethodToken () { Empty = new MethodToken (); }
public bool Equals(MethodToken obj) { return default(bool); }
internal void InternalSavePEFile(String fileName, MethodToken entryPoint, int isExe, bool isManifestFile) { _InternalSavePEFile(fileName, entryPoint.Token, isExe, isManifestFile); }
public MethodToken GetToken() { if (m_tkMethod.Token == 0) { if (m_link != null) m_link.GetToken(); int sigLength; byte[] sigBytes = GetMethodSignature().InternalGetSignature(out sigLength); m_tkMethod = new MethodToken (TypeBuilder.InternalDefineMethod( m_containingType.MetadataTokenInternal, m_strName, sigBytes, sigLength, Attributes, m_module)); if (m_inst != null) foreach (GenericTypeParameterBuilder tb in m_inst) if (!tb.m_type.IsCreated()) tb.m_type.CreateType(); TypeBuilder.InternalSetMethodImpl (m_module, MetadataTokenInternal, m_dwMethodImplFlags); } return m_tkMethod; }
static MethodToken() { Empty = new MethodToken(); }
[System.Security.SecurityCritical] // auto-generated private MethodToken GetTokenNoLock() { Contract.Assert(m_tkMethod.Token == 0, "m_tkMethod should not have been initialized"); int sigLength; byte[] sigBytes = GetMethodSignature().InternalGetSignature(out sigLength); int token = TypeBuilder.DefineMethod(m_module.GetNativeHandle(), m_containingType.MetadataTokenInternal, m_strName, sigBytes, sigLength, Attributes); m_tkMethod = new MethodToken(token); if (m_inst != null) foreach (GenericTypeParameterBuilder tb in m_inst) if (!tb.m_type.IsCreated()) tb.m_type.CreateType(); TypeBuilder.SetMethodImpl(m_module.GetNativeHandle(), token, m_dwMethodImplFlags); return m_tkMethod; }
public bool Equals(MethodToken obj) { return(this.tokValue == obj.tokValue); }
public bool Equals(MethodToken obj) { return (obj.m_method == this.m_method); }
/// <summary>Indicates whether the current instance is equal to the specified <see cref="T:System.Reflection.Emit.MethodToken" />.</summary><returns>true if the value of <paramref name="obj" /> is equal to the value of the current instance; otherwise, false.</returns><param name="obj">The <see cref="T:System.Reflection.Emit.MethodToken" /> to compare to the current instance.</param> public bool Equals(MethodToken obj) { throw new NotImplementedException(); }
internal static SignatureHelper GetMethodSigHelper (Module mod, MethodToken token) { lock(typeof(AssemblyBuilder)) { IntPtr context = ModuleToContext(mod); IntPtr sig = ClrSigCreateMethodCopy (context, mod.privateData, token.Token); return new SignatureHelper(mod, context, sig); } }
internal void SetEntryPoint(MethodToken entryPoint) { // Sets the entry point of the module to be a given method. If no entry point // is specified, calling EmitPEFile will generate a dll. // AssemblyBuilder.SetEntryPoint has already demanded required permission m_EntryPoint = entryPoint; }