private MethodDefinition FindMatchingMethod() { MethodDefinition result = null; var asmdef = PluginFactory.GetInstance().LoadAssembly(_compiler.AssemblyLocation, false); // Fix for inner types, remove namespace and owner. var typename = (_mdefsource.DeclaringType.IsNested) ? _mdefsource.DeclaringType.Name : _mdefsource.DeclaringType.FullName; // Generic hierarchy will push all generic parameters to the final type, so fix type name var tag = typename.LastIndexOf(BaseLanguageHelper.GenericTypeTag, StringComparison.Ordinal); if (tag >= 0) { typename = string.Concat(typename.Substring(0, tag + 1), _mdefsource.DeclaringType.GenericParameters.Count); } var tdef = CecilHelper.FindMatchingType(asmdef.MainModule, typename); if (tdef != null) { result = CecilHelper.FindMatchingMethod(tdef, _mdefsource); } return(result); }
private TypeDefinition GetTypeDefinition(TypeReference item) { ModuleDefinition moddef = null; if ((item.Scope) is ModuleDefinition) { moddef = (ModuleDefinition)item.Scope; // Force node lazy load for all candidates, we already have the module // ReSharper disable once ReturnValueOfPureMethodIsNotUsed GetAssemblyDefinitionsByNodeName(moddef.Assembly.Name.Name).ToList(); } else if ((item.Scope) is AssemblyNameReference) { var anr = (AssemblyNameReference)item.Scope; var asmdef = GetAssemblyDefinitionsByNodeName(anr.Name).FirstOrDefault(); if (asmdef != null) { moddef = asmdef.MainModule; } } if (moddef == null) { return(null); } var typedef = CecilHelper.FindMatchingType(moddef.Types, StripGenerics(item, item.FullName)); if (typedef == null) { return(null); } if (typedef.DeclaringType != null) { GetTypeDefinition(typedef.DeclaringType); } TreeNode moduleNode; TreeNode typeNode; if (_nodes.TryGetValue(moddef, out moduleNode)) { LoadNodeOnDemand(moduleNode); } if (_nodes.TryGetValue(typedef, out typeNode)) { LoadNodeOnDemand(typeNode); } return(typedef); }
private MethodDefinition FindMatchingMethod() { MethodDefinition result = null; AssemblyDefinition asmdef = AssemblyDefinition.ReadAssembly(_compiler.AssemblyLocation); // Fix for inner types, remove namespace and owner. string typename = (_mdefsource.DeclaringType.IsNested) ? _mdefsource.DeclaringType.Name : _mdefsource.DeclaringType.FullName; TypeDefinition tdef = CecilHelper.FindMatchingType(asmdef.MainModule, typename); if (tdef != null) { result = CecilHelper.FindMatchingMethod(tdef, _mdefsource); } return(result); }
public TypeDefinition GetTypeDefinition(TypeReference item) { ModuleDefinition moddef = null; if ((item.Scope) is ModuleDefinition) { moddef = (ModuleDefinition) item.Scope; GetAssemblyDefinitionByNodeName(moddef.Assembly.Name.Name); } else if ((item.Scope) is AssemblyNameReference) { AssemblyNameReference anr = (AssemblyNameReference) item.Scope; AssemblyDefinition asmdef = GetAssemblyDefinitionByNodeName(anr.Name); if (asmdef != null) { moddef = asmdef.MainModule; } } if (moddef != null) { TypeDefinition typedef = CecilHelper.FindMatchingType(moddef.Types, StripGenerics(item, item.FullName)); if (typedef != null) { if (typedef.DeclaringType != null) { GetTypeDefinition(typedef.DeclaringType); } LoadNodeOnDemand(m_nodes[moddef]); LoadNodeOnDemand(m_nodes[typedef]); return typedef; } } return null; }