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


C# Cci.AssemblyIdentity类代码示例

本文整理汇总了C#中Microsoft.Cci.AssemblyIdentity的典型用法代码示例。如果您正苦于以下问题:C# AssemblyIdentity类的具体用法?C# AssemblyIdentity怎么用?C# AssemblyIdentity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AssemblyIdentity类属于Microsoft.Cci命名空间,在下文中一共展示了AssemblyIdentity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CompileProject

        public Assembly CompileProject(string projectFileName)
        {
            Assembly existing;
            if (Compilations.TryGetValue(Path.GetFullPath(projectFileName), out existing))
            {
                return existing;
            }

            var project = new Microsoft.Build.BuildEngine.Project();
            project.Load(projectFileName);

            var projectName = Environment.NameTable.GetNameFor(project.EvaluatedProperties["AssemblyName"].Value);
            var projectPath = project.FullFileName;
            var compilerOptions = new SpecSharpOptions();
            var assemblyReferences = new List<IAssemblyReference>();
            var moduleReferences = new List<IModuleReference>();
            var programSources = new List<SpecSharpSourceDocument>();
            var assembly = new SpecSharpAssembly(projectName, projectPath, Environment, compilerOptions, assemblyReferences, moduleReferences, programSources);
            var helper = new SpecSharpCompilationHelper(assembly.Compilation);

            Compilations[Path.GetFullPath(projectFileName)] = assembly;

            assemblyReferences.Add(Environment.LoadAssembly(Environment.CoreAssemblySymbolicIdentity));
            project.Build("ResolveAssemblyReferences");
            foreach (BuildItem item in project.GetEvaluatedItemsByName("ReferencePath"))
            {
                var assemblyName = new System.Reflection.AssemblyName(item.GetEvaluatedMetadata("FusionName"));
                var name = Environment.NameTable.GetNameFor(assemblyName.Name);
                var culture = assemblyName.CultureInfo != null ? assemblyName.CultureInfo.Name : "";
                var version = assemblyName.Version == null ? new Version(0, 0) : assemblyName.Version;
                var token = assemblyName.GetPublicKeyToken();
                if (token == null) token = new byte[0];
                var location = item.FinalItemSpec;
                var identity = new AssemblyIdentity(name, culture, version, token, location);
                var reference = Environment.LoadAssembly(identity);
                assemblyReferences.Add(reference);
            }

            foreach (BuildItem item in project.GetEvaluatedItemsByName("ProjectReference"))
            {
                var name = Environment.NameTable.GetNameFor(Path.GetFileNameWithoutExtension(item.FinalItemSpec));
                var location = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(project.FullFileName), item.FinalItemSpec));
                var reference = CompileProject(location);
                assemblyReferences.Add(reference);
            }

            foreach (BuildItem item in project.GetEvaluatedItemsByName("Compile"))
            {
                var location = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(project.FullFileName), item.FinalItemSpec));
                var name = Environment.NameTable.GetNameFor(location);
                var programSource = new SpecSharpSourceDocument(helper, name, location, File.ReadAllText(location));
                programSources.Add(programSource);
            }

            return assembly;
        }
开发者ID:dbremner,项目名称:specsharp,代码行数:56,代码来源:MSBuildCompiler.cs

示例2: 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(AssemblyIdentity assemblyIdentity, IMetadataHost metadataHost) {
      lock (GlobalLock.LockingObject) {
#if COMPACTFX
        var gacKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"\Software\Microsoft\.NETCompactFramework\Installer\Assemblies\Global");
        foreach (var gacName in gacKey.GetValueNames()) {
          if (IdentityMatchesString(assemblyIdentity, gacName)) {
            var values = gacKey.GetValue(gacName) as string[];
            if (values == null || values.Length == 0) continue;
            return values[0];
          }
        }
        return null;
#else
        if (!GlobalAssemblyCache.FusionLoaded) {
          GlobalAssemblyCache.FusionLoaded = true;
          System.Reflection.Assembly systemAssembly = typeof(object).Assembly;
          //^ assume systemAssembly != null;
          string/*?*/ systemAssemblyLocation = systemAssembly.Location;
          //^ assume systemAssemblyLocation != null;
          string dir = Path.GetDirectoryName(systemAssemblyLocation);
          //^ 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 cn = new AssemblyName(currentName);
          if (assemblyIdentity.Equals(new AssemblyIdentity(metadataHost.NameTable.GetNameFor(cn.Name), cn.Culture, cn.Version, cn.PublicKeyToken, ""))) {
            string codeBase = cn.CodeBase;
            if (codeBase != null && codeBase.StartsWith("file://")) {
              Uri u = new Uri(codeBase, UriKind.Absolute);
              return u.LocalPath;
            }
            return cn.GetLocation();
          }
        }
        return null;
#endif
      }
    }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:48,代码来源:GlobalAssemblyCache.cs

示例3: UnifyAssembly

        public override AssemblyIdentity UnifyAssembly(AssemblyIdentity assemblyIdentity)
        {
            Dictionary<String, Byte[]> assembliesToUnify = new Dictionary<string, Byte[]>{
                {"System", new Byte[]{0xb7,0x7a,0x5c,0x56,0x19,0x34,0xe0,0x89}},
                {"System.Drawing", new Byte[]{0xb0,0x3f,0x5f,0x7f,0x11,0xd5,0x0a,0x3a}},
                {"System.Windows.Forms", new Byte[]{0xb7,0x7a,0x5c,0x56,0x19,0x34,0xe0,0x89}},
            };
            Byte[] publicKeyToken;

            if (assembliesToUnify.TryGetValue(assemblyIdentity.Name.Value, out publicKeyToken) && IteratorHelper.EnumerablesAreEqual<Byte>(publicKeyToken, assemblyIdentity.PublicKeyToken))
            {
                assemblyIdentity = new AssemblyIdentity(
                    assemblyIdentity.Name,
                    assemblyIdentity.Culture,
                    CoreAssemblySymbolicIdentity.Version, // roll forward to the version of mscorlib
                    assemblyIdentity.PublicKeyToken,
                    assemblyIdentity.Location);
            }

            return base.UnifyAssembly(assemblyIdentity);
        }
开发者ID:dsgouda,项目名称:buildtools,代码行数:21,代码来源:HostEnvironment.cs

示例4: ResolvingAssemblyReference

        // TODO: Something similar for ResolvingModuleReference?
        public override void ResolvingAssemblyReference(IUnit referringUnit, AssemblyIdentity referencedAssembly)
        {
            List<String> paths = new List<string>();
            paths.Add(Path.GetDirectoryName(referringUnit.Location));
            paths.AddRange(_assemblyPaths);

            foreach (String assemblyFile in _referencedAssemblies)
            {
                if (Path.GetFileNameWithoutExtension(assemblyFile).Equals(referencedAssembly.Name.Value, StringComparison.OrdinalIgnoreCase))
                {
                    if (TryLoadAssembly(referringUnit, referencedAssembly, assemblyFile))
                    {
                        return;
                    }
                }
            }

            foreach (String path in paths)
            {
                String file = Path.Combine(path, referencedAssembly.Name.Value + ".dll");
                if (TryLoadAssembly(referringUnit, referencedAssembly, file))
                {
                    return;
                }

                file = Path.Combine(path, referencedAssembly.Name.Value + ".exe");
                if (TryLoadAssembly(referringUnit, referencedAssembly, file))
                {
                    return;
                }

                file = Path.Combine(path, referencedAssembly.Name.Value + ".winmd");
                if (TryLoadAssembly(referringUnit, referencedAssembly, file))
                {
                    return;
                }
            }

            throw new Exception(String.Format("Cannot find: {0}. Check assembly dependency paths.", referencedAssembly.ToString()));
        }
开发者ID:dsgouda,项目名称:buildtools,代码行数:41,代码来源:HostEnvironment.cs

示例5: Map

    public IAssemblyReference Map(R.IAssemblySymbol assembly) {
      Contract.Requires(assembly != null);
      Contract.Ensures(Contract.Result<IAssemblyReference>() != null);

      IAssemblyReference cciAssembly = null;
      if (!assemblySymbolCache.TryGetValue(assembly, out cciAssembly)) {
        var an = assembly.Identity;
        IEnumerable<byte> pkt = an.PublicKeyToken.AsEnumerable();
        if (pkt == null)
          pkt = new byte[0];
        var identity = new Microsoft.Cci.AssemblyIdentity(
          this.nameTable.GetNameFor(an.Name),
          an.CultureName == null ? "" : an.CultureName, // REVIEW: This can't be right
          an.Version,
          pkt,
          an.Location == null ? "unknown://location" : an.Location
          );
        cciAssembly = new Microsoft.Cci.Immutable.AssemblyReference(this.host, identity);
        assemblySymbolCache[assembly] = cciAssembly;
      }
      Contract.Assume(cciAssembly != null);
      return cciAssembly;
    }
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:23,代码来源:ReferenceMapper.cs

示例6: ResolvingAssemblyReference

 /// <summary>
 /// This method is called when the assembly reference is being resolved and its not already loaded by the Read/Write host.
 /// </summary>
 /// <param name="referringUnit">The unit that is referencing the assembly.</param>
 /// <param name="referencedAssembly">Assembly identity for the assembly being referenced.</param>
 public virtual void ResolvingAssemblyReference(IUnit referringUnit, AssemblyIdentity referencedAssembly) {
   if (!string.IsNullOrEmpty(referencedAssembly.Location)) {
     this.LoadUnit(referencedAssembly);
   } else {
     AssemblyIdentity ai = this.ProbeAssemblyReference(referringUnit, referencedAssembly);
     if (ai != null && !String.IsNullOrEmpty(ai.Location)) {
       this.LoadUnit(ai);
     }
   }
 }
开发者ID:Refresh06,项目名称:visualmutator,代码行数:15,代码来源:Core.cs

示例7: AssemblyStore

 internal AssemblyStore(
   AssemblyIdentity assemblyIdentity,
   uint internedId,
   uint rootNamespaceInternedId
 ) {
   this.AssemblyIdentity = assemblyIdentity;
   this.InternedIdWithCount = internedId;
   this.RootNamespaceInternedId = rootNamespaceInternedId;
 }
开发者ID:Refresh06,项目名称:visualmutator,代码行数:9,代码来源:Core.cs

示例8: ModuleIdentity

 /// <summary>
 /// Allocates an object that identifies a .NET module that forms part of an assembly.
 /// Can be just the name of the module along with the identifier of the assembly, but can also include the location where the module is stored.
 /// </summary>
 /// <param name="name">The name of the identified module.</param>
 /// <param name="location">The location where the module is stored. Can be the empty string if the location is not known. The location need not be a file path.</param>
 /// <param name="containingAssembly">The identifier of the assembly to which the identified module belongs. May be null.</param>
 public ModuleIdentity(IName name, string location, AssemblyIdentity/*?*/ containingAssembly)
   : base(name, location) {
   Contract.Requires(name != null);
   Contract.Requires(location != null);
   this.containingAssembly = containingAssembly;
 }
开发者ID:RUB-SysSec,项目名称:Probfuscator,代码行数:13,代码来源:Units.cs

示例9: UnifyAssembly

 public AssemblyIdentity UnifyAssembly(AssemblyIdentity assemblyIdentity) {
   throw new NotImplementedException();
 }
开发者ID:Refresh06,项目名称:visualmutator,代码行数:3,代码来源:Core.cs

示例10: LoadAssembly

 /// <summary>
 /// The assembly that matches the given reference, or a dummy assembly if no matching assembly can be found.
 /// </summary>
 public virtual IAssembly LoadAssembly(AssemblyIdentity assemblyIdentity) {
   IUnit/*?*/ unit;
   lock (GlobalLock.LockingObject) {
     this.unitCache.TryGetValue(assemblyIdentity, out unit);
   }
   IAssembly/*?*/ result;
   if (unit != null)
     result = unit as IAssembly;
   else {
     if (string.IsNullOrEmpty(assemblyIdentity.Location) || string.Equals(assemblyIdentity.Location, "unknown://location", StringComparison.OrdinalIgnoreCase)) {
       result = Dummy.Assembly;
       lock (GlobalLock.LockingObject) {
         this.unitCache.Add(assemblyIdentity, result);
       }
     } else {
       unit = this.LoadUnitFrom(assemblyIdentity.Location);
       result = unit as IAssembly;
       if (result != null && this.UnifyAssembly(result).Equals(assemblyIdentity))
         lock (GlobalLock.LockingObject) {
           this.unitCache[assemblyIdentity] = result;
           this.coreIdentities.Add(result.CoreAssemblySymbolicIdentity);
         }
     }
   }
   if (result == null) result = Dummy.Assembly;
   return result;
 }
开发者ID:Refresh06,项目名称:visualmutator,代码行数:30,代码来源:Core.cs

示例11: ProbeAssemblyReference

    public virtual AssemblyIdentity ProbeAssemblyReference(IUnit referringUnit, AssemblyIdentity referencedAssembly) {
      AssemblyIdentity result;

      if (!string.IsNullOrEmpty(referringUnit.Location)) {
        // probe for in the same directory as the referring unit
        var referringDir = Path.GetDirectoryName(Path.GetFullPath(referringUnit.Location));
        result = this.Probe(referringDir, referencedAssembly);
        if (result != null) return result;
      }

      // Probe in the libPaths directories
      foreach (string libPath in this.LibPaths) {
        Contract.Assume(libPath != null);
        result = this.Probe(libPath, referencedAssembly);
        if (result != null) return result;
      }

      // Check GAC
#if !COMPACTFX
      if (this.SearchInGAC) {
        string/*?*/ gacLocation = GlobalAssemblyCache.GetLocation(referencedAssembly, this);
        if (gacLocation != null) {
          return new AssemblyIdentity(referencedAssembly, gacLocation);
        }
      }
#endif

      // Check platform location
      var platformDir = Path.GetDirectoryName(Path.GetFullPath(GetLocalPath(typeof(object).Assembly.GetName())))??"";
      var coreVersion = this.CoreAssemblySymbolicIdentity.Version;
      if (coreVersion.Major == 1) {
        if (coreVersion.Minor == 0)
          platformDir = Path.Combine(Path.GetDirectoryName(platformDir)??"", "v1.0.3705");
        else if (coreVersion.Minor == 1)
          platformDir = Path.Combine(Path.GetDirectoryName(platformDir)??"", "v1.1.4322");
      } else if (coreVersion.Major == 2) {
        platformDir = Path.Combine(Path.GetDirectoryName(platformDir)??"", "v3.5");
        result = this.Probe(platformDir, referencedAssembly);
        if (result != null) return result;
        platformDir = Path.Combine(Path.GetDirectoryName(platformDir)??"", "v3.0");
        result = this.Probe(platformDir, referencedAssembly);
        if (result != null) return result;
        platformDir = Path.Combine(Path.GetDirectoryName(platformDir)??"", "v2.0.50727");
      } else if (coreVersion.Major == 4) {
        platformDir = Path.Combine(Path.GetDirectoryName(platformDir)??"", "v4.0.30319");
      }

      result = this.Probe(platformDir, referencedAssembly);
      if (result != null) return result;

      // Give up
      return new AssemblyIdentity(referencedAssembly, "unknown://location");
    }
开发者ID:Refresh06,项目名称:visualmutator,代码行数:53,代码来源:Core.cs

示例12: Probe

 /// <summary>
 /// Looks in the specified <paramref name="probeDir"/> to see if a file
 /// exists, first with the extension "dll" and then with the extension "exe".
 /// Returns null if not found, otherwise constructs a new AssemblyIdentity
 /// </summary>
 private AssemblyIdentity/*?*/ Probe(string probeDir, AssemblyIdentity referencedAssembly) {
   string path = Path.Combine(probeDir, referencedAssembly.Name.Value + ".dll");
   if (File.Exists(path)) return new AssemblyIdentity(referencedAssembly, path);
   path = Path.Combine(probeDir, referencedAssembly.Name.Value + ".exe");
   if (File.Exists(path)) return new AssemblyIdentity(referencedAssembly, path);
   return null;
 }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:12,代码来源:Core.cs

示例13: lock

    // Interning of module and assembly
    // enables fast comparision of the nominal types. The interned module id takes into account the unification policy applied by the host.
    // For example if mscorlib 1.0 and mscorlib 2.0 is unified by the host both of them will have same intered id, otherwise not.
    // Interned id is 32 bit integer. it is split into 22 bit part and 10 bit part. First part represents the assembly and other part represents module.
    // Simple module which are not part of any assembly is represented by 0 in assembly part and number in module part.
    // Main module of the assembly is represented with something in the assembly part and 0 in the module part.
    // Other modules of the multimodule assembly are represented with assembly part being containing assembly and module part distinct for each module.
    // Note that this places limit on number of modules that can be loaded to be 2^20 and number of modules loaded at 2^12

    uint IInternFactory.GetAssemblyInternedKey(AssemblyIdentity assemblyIdentity) {
      lock (GlobalLock.LockingObject) {
        AssemblyStore assemblyStore = this.GetAssemblyStore(assemblyIdentity);
        return assemblyStore.InternedId;
      }
    }
开发者ID:Refresh06,项目名称:visualmutator,代码行数:15,代码来源:Core.cs

示例14: LoadAssembly

 /// <summary>
 /// The assembly that matches the given reference, or a dummy assembly if no matching assembly can be found.
 /// </summary>
 public virtual IAssembly LoadAssembly(AssemblyIdentity assemblyIdentity) {
   IUnit/*?*/ unit;
   lock (GlobalLock.LockingObject) {
     this.unitCache.TryGetValue(assemblyIdentity, out unit);
   }
   if (unit == null) {
     if (assemblyIdentity.Location == "" || assemblyIdentity.Location == "unknown://location") {
       unit = Dummy.Assembly;
       this.unitCache.Add(assemblyIdentity, unit);
     } else {
       unit = this.LoadUnitFrom(assemblyIdentity.Location);
       var assembly = unit as IAssembly;
       if (assembly != null && this.UnifyAssembly(assembly.AssemblyIdentity).Equals(assemblyIdentity))
         this.unitCache[assemblyIdentity] = unit;
     }
   }
   IAssembly/*?*/ result = unit as IAssembly;
   if (result == null) result = Dummy.Assembly;
   return result;
 }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:23,代码来源:Core.cs

示例15: ProbeAssemblyReference

 /// <summary>
 /// Given the identity of a referenced assembly (but not its location), apply host specific policies for finding the location
 /// of the referenced assembly.
 /// </summary>
 /// <param name="referringUnit">The unit that is referencing the assembly. It will have been loaded from somewhere and thus
 /// has a known location, which will typically be probed for the referenced assembly.</param>
 /// <param name="referencedAssembly">The assembly being referenced. This will not have a location since there is no point in probing
 /// for the location of an assembly when you already know its location.</param>
 /// <returns>
 /// An assembly identity that matches the given referenced assembly identity, but which includes a location.
 /// If the probe failed to find the location of the referenced assembly, the location will be "unknown://location".
 /// </returns>
 /// <remarks>
 /// Default implementation of ProbeAssemblyReference. Override this method to change its behavior.
 /// </remarks>
 //^ [Pure]
 public virtual AssemblyIdentity ProbeAssemblyReference(IUnit referringUnit, AssemblyIdentity referencedAssembly) {
   return new AssemblyIdentity(referencedAssembly, "unknown://location");
 }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:19,代码来源:Core.cs


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