public static uint GetGlobalStaticConstructor(IMetaDataImport mdi) { var mdTokens = MDAPI.GetMethodTokens(mdi, 0x02000001); foreach (uint mdToken in mdTokens) { string name = MDAPI.GetMethodName(mdi, mdToken); if (name != ".cctor") { continue; } if (!MDAPI.GetMethodAttributes(mdi, mdToken, out var attrs, out var implAttrs)) { continue; } if ((attrs & MethodAttributes.RTSpecialName) == 0) { continue; } if ((attrs & MethodAttributes.Static) == 0) { continue; } return(mdToken); } return(0); }
static CorMethodInfo ReadMethodInfo(IMetaDataImport mdi, uint token, CorType type) { if (mdi == null) { return(null); } var name = MDAPI.GetMethodName(mdi, token); if (name == null) { return(null); } if (!MDAPI.GetMethodAttributes(mdi, token, out var attrs, out var implAttrs)) { return(null); } var sig = GetMethodSignature(mdi, token); if (sig == null) { return(null); } bool compilerGeneratedAttribute = GetCompilerGeneratedAttribute(mdi, token); return(new CorMethodInfo(type, token, name, sig, attrs, implAttrs, compilerGeneratedAttribute)); }
/// <summary> /// Finds all constructors /// </summary> /// <returns></returns> public CorFunction[] FindConstructors() { var ctors = new List <CorFunction>(); var mod = Module; var mdi = mod?.GetMetaDataInterface <IMetaDataImport>(); foreach (var mdToken in MDAPI.GetMethodTokens(mdi, token)) { MethodAttributes attrs; MethodImplAttributes implAttrs; if (!MDAPI.GetMethodAttributes(mdi, mdToken, out attrs, out implAttrs)) { continue; } if ((attrs & MethodAttributes.RTSpecialName) == 0) { continue; } if (MDAPI.GetMethodName(mdi, mdToken) != ".ctor") { continue; } var ctor = mod.GetFunctionFromToken(mdToken); Debug.Assert(ctor != null); if (ctor != null) { ctors.Add(ctor); } } return(ctors.ToArray()); }
/// <summary> /// Finds methods /// </summary> /// <param name="name">Method name</param> /// <returns></returns> public IEnumerable <CorFunction> FindFunctions(string name, bool checkBaseClasses = true) { var mod = Module; var mdi = mod?.GetMetaDataInterface <IMetaDataImport>(); foreach (var mdToken in MDAPI.GetMethodTokens(mdi, token)) { if (MDAPI.GetMethodName(mdi, mdToken) == name) { var func = mod.GetFunctionFromToken(mdToken); Debug.Assert(func != null); if (func != null) { yield return(func); } } } if (checkBaseClasses) { var type = GetParameterizedType(CorElementType.Class); if (type != null) { type = type.Base; } if (type != null) { foreach (var func in type.FindFunctions(name, checkBaseClasses)) { yield return(func); } } } }
/// <summary> /// Finds methods /// </summary> /// <param name="name">Method name</param> /// <returns></returns> public IEnumerable <CorFunction> FindFunctions(string name, bool checkBaseClasses = true) { for (var type = this; type != null; type = type.Base) { if (!checkBaseClasses && (object)this != (object)type) { break; } if (!type.HasClass) { continue; } var cls = type.Class; if (cls == null) { continue; } var mod = cls.Module; var mdi = mod == null ? null : mod.GetMetaDataInterface <IMetaDataImport>(); foreach (var mdToken in MDAPI.GetMethodTokens(mdi, cls.Token)) { if (MDAPI.GetMethodName(mdi, mdToken) == name) { var func = mod.GetFunctionFromToken(mdToken); Debug.Assert(func != null); if (func != null) { yield return(func); } } } } }
/// <summary> /// Gets method parameters and method flags /// </summary> /// <param name="methodAttrs">Method attributes</param> /// <param name="methodImplAttrs">Method implementation attributes</param> /// <returns></returns> public MDParameters GetMDParameters(out MethodAttributes methodAttrs, out MethodImplAttributes methodImplAttrs) { methodAttrs = 0; methodImplAttrs = 0; var mod = Module; if (mod == null) { return(null); } var mdi = mod.GetMetaDataInterface <IMetaDataImport>(); if (mdi == null) { return(null); } if (!MDAPI.GetMethodAttributes(mdi, Token, out methodAttrs, out methodImplAttrs)) { return(null); } var name = MDAPI.GetMethodName(mdi, Token); if (name == null) { return(null); } return(MetaDataUtils.GetParameters(mdi, Token)); }
public string GetName() { var mod = Module; var mdi = mod == null ? null : mod.GetMetaDataInterface <IMetaDataImport>(); if (mdi == null) { return(null); } return(MDAPI.GetMethodName(mdi, Token)); }
void InitNameAndAttributes_NoLock() { var mdi = readerModule.MetaDataImport; uint token = OriginalToken.Raw; Name = Utils.GetUTF8String(MDAPI.GetUtf8Name(mdi, OriginalToken.Raw), MDAPI.GetMethodName(mdi, token) ?? string.Empty); MDAPI.GetMethodAttributes(mdi, token, out var attrs, out var implAttrs); Attributes = attrs; ImplAttributes = implAttrs; origAttributes = attrs; origImplAttributes = implAttrs; }
public string GetName() => MDAPI.GetMethodName(Module?.GetMetaDataInterface <IMetaDataImport>(), Token);