public string GetAssemblyName(IMetadataScope scope) { if (scope is ModuleDefinition scopeModule) { return(scopeModule.Assembly.FullName); } if (scope is AssemblyNameReference assemblyNameReference) { return(assemblyNameReference.FullName); } else { throw new Exception($"Assembly ensure does not support scope '{scope.GetType().FullName}'"); } }
/// <summary> /// Returns the full assembly name corresponding to <paramref name="scope"/>. /// </summary> public static string GetFullName(this IMetadataScope scope) { var md = scope as ModuleDefinition; if (md != null) { return(md.Assembly.Name.FullName); } var nr = scope as AssemblyNameReference; if (nr != null) { return(nr.FullName); } throw new NotSupportedException(String.Format("Unknown metadata scope type {0}", scope.GetType().FullName)); }
void EmitScope(IMetadataScope s, StringBuilder sb) { if (s is AssemblyNameReference) { AssemblyNameReference aname = (s as AssemblyNameReference); sb.Append("[" + EscapeName(aname.Name) + "]"); } else if (s is ModuleDefinition) { if (s != main) { throw new NotImplementedException(); } } else { throw new NotImplementedException(s.GetType().ToString()); } }
private string GetScopeName(IMetadataScope scope) { if (scope == null) { return(String.Empty); } ModuleDefinition md = (scope as ModuleDefinition); if (md != null) { return(md.Name.Replace(", ", ",\\n")); } AssemblyNameReference anr = (scope as AssemblyNameReference); if (anr != null) { return(anr.FullName.Replace(", ", ",\\n")); } Console.WriteLine("GetScopeName {0}", scope.GetType()); return(String.Empty); }
public static string getCanonicalizedScopeName(IMetadataScope scope) { AssemblyNameReference asmRef = null; switch (scope.MetadataScopeType) { case MetadataScopeType.AssemblyNameReference: asmRef = (AssemblyNameReference)scope; break; case MetadataScopeType.ModuleDefinition: var module = (ModuleDefinition)scope; if (module.Assembly != null) asmRef = module.Assembly.Name; break; case MetadataScopeType.ModuleReference: break; default: throw new ApplicationException(string.Format("Invalid scope type: {0}", scope.GetType())); } if (asmRef != null) { // The version number should be ignored. Older code may reference an old version of // the assembly, but if the newer one has been loaded, that one is used. return asmRef.Name.ToLowerInvariant(); } return string.Format("{0}", scope.ToString().ToLowerInvariant()); }
private string GetScopeName (IMetadataScope scope) { if (scope == null) return String.Empty; ModuleDefinition md = (scope as ModuleDefinition); if (md != null) return md.Name.Replace (", ", ",\\n"); AssemblyNameReference anr = (scope as AssemblyNameReference); if (anr != null) return anr.FullName.Replace (", ", ",\\n"); Console.WriteLine ("GetScopeName {0}", scope.GetType ()); return String.Empty; }
public static AssemblyNameReference getAssemblyNameReference(IMetadataScope scope) { if (scope is ModuleDefinition) { var moduleDefinition = (ModuleDefinition)scope; return moduleDefinition.Assembly.Name; } else if (scope is AssemblyNameReference) return (AssemblyNameReference)scope; throw new ApplicationException(string.Format("Unknown IMetadataScope type: {0}", scope.GetType())); }
void EmitScope (IMetadataScope s, StringBuilder sb) { if (s is AssemblyNameReference) { AssemblyNameReference aname = (s as AssemblyNameReference); sb.Append ("[" + EscapeName (aname.Name) + "]"); } else if (s is ModuleDefinition) { if (s != main) throw new NotImplementedException (); } else { throw new NotImplementedException (s.GetType ().ToString ()); } }
// Returns null if it's a non-loaded module/assembly IEnumerable<Module> findModules(IMetadataScope scope) { if (scope is AssemblyNameReference) { var assemblyRef = (AssemblyNameReference)scope; var moduleHash = assemblyHash.lookup(assemblyRef.ToString()); if (moduleHash != null) return moduleHash.Modules; } else if (scope is ModuleDefinition) { var moduleDefinition = (ModuleDefinition)scope; var module = modulesDict.lookup(moduleDefinition.FullyQualifiedName); if (module != null) return new List<Module> { module }; } else throw new ApplicationException(string.Format("IMetadataScope is an unsupported type: {0}", scope.GetType())); return null; }