public bool TryGetMetadata(FileKey key, out AssemblyMetadata metadata)
 {
     lock (_gate)
     {
         return TryGetMetadata_NoLock(key, out metadata);
     }
 }
示例#2
0
 // creates a copy
 private AssemblyMetadata(AssemblyMetadata other)
     : base(isImageOwner: false, id: other.Id)
 {
     this.CachedSymbols = other.CachedSymbols;
     _lazyData = other._lazyData;
     _moduleFactoryOpt = other._moduleFactoryOpt;
     _initialModules = other._initialModules;
     // Leave lazyPublishedModules unset. Published modules will be set and copied as needed.
 }
            private bool TryGetMetadata_NoLock(FileKey key, out AssemblyMetadata metadata)
            {
                if (_metadataCache.TryGetValue(key, out var metadataSource))
                {
                    metadata = metadataSource.GetValue();
                    return metadata != null;
                }

                metadata = null;
                return false;
            }
            public bool TryGetOrAddMetadata(FileKey key, ValueSource<AssemblyMetadata> newMetadata, out AssemblyMetadata metadata)
            {
                lock (_gate)
                {
                    if (TryGetMetadata_NoLock(key, out metadata))
                    {
                        return false;
                    }

                    EnsureCapacity_NoLock();

                    metadata = newMetadata.GetValue();
                    Contract.ThrowIfNull(metadata);

                    // don't use "Add" since key might already exist with already released metadata
                    _metadataCache[key] = newMetadata;
                    return true;
                }
            }
        /// <exception cref="BadImageFormatException"/>
        internal PEAssembly(AssemblyMetadata owner, ImmutableArray<PEModule> modules)
        {
            Debug.Assert(!modules.IsDefault);
            Debug.Assert(modules.Length > 0);

            this.identity = modules[0].ReadAssemblyIdentityOrThrow();

            var refs = ArrayBuilder<AssemblyIdentity>.GetInstance();
            int[] refCounts = new int[modules.Length];

            for (int i = 0; i < modules.Length; i++)
            {
                ImmutableArray<AssemblyIdentity> refsForModule = modules[i].ReferencedAssemblies;
                refCounts[i] = refsForModule.Length;
                refs.AddRange(refsForModule);
            }

            this.modules = modules;
            this.AssemblyReferences = refs.ToImmutableAndFree();
            this.ModuleReferenceCounts = refCounts.AsImmutableOrNull();
            this.owner = owner;
        }
        /// <exception cref="IOException"/>
        /// <exception cref="BadImageFormatException" />
        private bool TryCreateAssemblyMetadataFromMetadataImporter(FileKey fileKey, out AssemblyMetadata metadata)
        {
            metadata = default(AssemblyMetadata);

            var manifestModule = TryCreateModuleMetadataFromMetadataImporter(fileKey);
            if (manifestModule == null)
            {
                return false;
            }

            metadata = CreateAssemblyMetadata(fileKey, manifestModule, null, CreateModuleMetadata);
            return true;
        }
示例#7
0
            public CachedAssembly(AssemblyMetadata metadata)
            {
                Debug.Assert(metadata != null);

                // Save a reference to the cached symbols so that they don't get collected 
                // if the metadata object gets collected.
                this.CachedSymbols = metadata.CachedSymbols;

                this.Metadata = new WeakReference<AssemblyMetadata>(metadata);
            }
示例#8
0
 private AssemblyMetadata(AssemblyMetadata metadata)
 {
     this.Assembly = metadata.Assembly;
     this.CachedSymbols = metadata.CachedSymbols;
     this.Modules = metadata.Modules.SelectAsArray(module => module.Copy());
 }
 /// <summary>
 /// Creates a reference to a single-module assembly image.
 /// </summary>
 /// <param name="assemblyImage">Stream with assembly image, it should support seek operations.</param>
 /// <param name="documentation">Provides XML documentation for symbol found in the reference.</param>
 /// <param name="aliases">Reference alias.</param>
 /// <param name="embedInteropTypes">True if interop types contained in the reference should be embedded to the compilation that uses the reference.</param>
 /// <param name="filePath">Optional path that describes the location of the metadata. The file doesn't need to exist on disk. The path is opaque to the compiler.</param>
 /// <param name="display">Display string for error reporting.</param>
 public MetadataImageReference(System.IO.Stream assemblyImage, DocumentationProvider documentation = null, ImmutableArray <string> aliases = default(ImmutableArray <string>), bool embedInteropTypes = false, string filePath = null, string display = null)
     : this(AssemblyMetadata.CreateFromImageStream(RequireNonNull(assemblyImage, "assemblyImage")), documentation, aliases, embedInteropTypes, filePath, display)
 {
 }
 /// <summary>
 /// Creates a reference to a single-module assembly image.
 /// </summary>
 /// <param name="assemblyImage">Stream with assembly image, it should support seek operations.</param>
 /// <param name="documentation">Provides XML documentation for symbol found in the reference.</param>
 /// <param name="alias">Reference alias.</param>
 /// <param name="embedInteropTypes">True if interop types contained in the reference should be embedded to the compilation that uses the reference.</param>
 /// <param name="fullPath">Optional full path used for reference comparison when used in compilation. The file doesn't need to exist.</param>
 /// <param name="display">Display string for error reporting.</param>
 public MetadataImageReference(System.IO.Stream assemblyImage, DocumentationProvider documentation = null, string alias = null, bool embedInteropTypes = false, string fullPath = null, string display = null)
     : this(AssemblyMetadata.CreateFromImageStream(RequireNonNull(assemblyImage, "assemblyImage")), documentation, alias, embedInteropTypes, fullPath, display)
 {
 }
示例#11
0
 private AssemblyMetadata(AssemblyMetadata metadata)
 {
     this.Assembly      = metadata.Assembly;
     this.CachedSymbols = metadata.CachedSymbols;
     this.Modules       = metadata.Modules.SelectAsArray(module => module.Copy());
 }