当前位置: 首页>>代码示例>>C#>>正文


C# AssemblyName.GetLocation方法代码示例

本文整理汇总了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;
   }
 }
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:33,代码来源:AssemblyCache.cs


注:本文中的AssemblyName.GetLocation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。