本文整理汇总了C#中AssemblyName.GetLocation方法的典型用法代码示例。如果您正苦于以下问题:C# AssemblyName.GetLocation方法的具体用法?C# AssemblyName.GetLocation怎么用?C# AssemblyName.GetLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AssemblyName
的用法示例。
在下文中一共展示了AssemblyName.GetLocation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetLocation
/// <summary>
/// Returns the original location of the corresponding assembly if available, otherwise returns the location of the shadow copy.
/// If the corresponding assembly is not in the GAC, null is returned.
/// </summary>
public static string GetLocation(AssemblyReference assemblyReference){
if (assemblyReference == null) { Debug.Fail("assemblyReference == null"); return null; }
lock(GlobalAssemblyCache.Lock){
if (!GlobalAssemblyCache.FusionLoaded){
GlobalAssemblyCache.FusionLoaded = true;
System.Reflection.Assembly systemAssembly = typeof(object).Assembly;
//^ assume systemAssembly != null && systemAssembly.Location != null;
string dir = Path.GetDirectoryName(systemAssembly.Location);
//^ assume dir != null;
GlobalAssemblyCache.LoadLibrary(Path.Combine(dir, "fusion.dll"));
}
IAssemblyEnum assemblyEnum;
CreateAssemblyEnum(out assemblyEnum, null, null, ASM_CACHE.GAC, 0);
if (assemblyEnum == null) return null;
IApplicationContext applicationContext;
IAssemblyName currentName;
while (assemblyEnum.GetNextAssembly(out applicationContext, out currentName, 0) == 0){
//^ assume currentName != null;
AssemblyName aName = new AssemblyName(currentName);
if (assemblyReference.Matches(aName.Name, aName.Version, aName.Culture, aName.PublicKeyToken)){
string codeBase = aName.CodeBase;
if (codeBase != null && codeBase.StartsWith("file:///"))
return codeBase.Substring(8);
return aName.GetLocation();
}
}
return null;
}
}