Esempio n. 1
0
        /// <summary>
        /// This method's custom attributes, empty if none
        /// </summary>
        override public ImmutableArray <MrCustomAttribute> GetCustomAttributes()
        {
            var customAttributeHandles = this.MethodDefinition.GetCustomAttributes();
            var customAttributes       = MrAssembly.GetCustomAttributesFromHandles(customAttributeHandles, this.DeclaringType);

            return(customAttributes.ToImmutableArray());
        }
        /// <summary>
        /// Load an assembly from its MetadataReader. If reader is null, create a fake assembly.
        /// </summary>
        private MrAssembly LoadFromReader(MetadataReader reader, string name, string path, bool implicitLoad)
        {
            if (!_loading && !implicitLoad)
            {
                throw new Exception("Once FinishLoading() has been called, no more assemblies can be loaded");
            }

            MrAssembly newAssembly;

            if (reader == null)
            {
                newAssembly = MrAssembly.CreateFakeAssembly(name, this);
            }
            else
            {
                Debug.Assert(name == reader.GetString(reader.GetAssemblyDefinition().Name) || name == "mscorlib");

                // See if the assembly was already explicitly loaded
                if (_loadedAssemblies.TryGetValue(name, out var loadedAssembly))
                {
                    return(loadedAssembly);
                }

                // Or it might have been implicitly loaded
                if (_implicitAssemblies.TryGetValue(name, out loadedAssembly))
                {
                    if (implicitLoad)
                    {
                        return(loadedAssembly);
                    }

                    // This assembly was implicitly loaded, now it's being explicitly loaded,
                    // so move it from implicit to explicit.
                    _loadedAssemblies[name] = loadedAssembly;
                    _implicitAssemblies.Remove(name);
                    return(loadedAssembly);
                }

                // Prevent stack overflow by making this assembly exist before creating it
                // (which might trigger a cycle of assembly references)
                if (implicitLoad)
                {
                    _implicitAssemblies[name] = null;
                }

                newAssembly = MrAssembly.Create(reader, path, this);
            }

            // Save the assembly
            if (implicitLoad)
            {
                _implicitAssemblies[name] = newAssembly;
            }
            else
            {
                _loadedAssemblies[name] = newAssembly;
            }

            return(newAssembly);
        }
Esempio n. 3
0
        internal static MrAssembly CreateFakeAssembly(string name, MrLoadContext loadContext)
        {
            var mrAssembly = new MrAssembly(null, null, loadContext);

            mrAssembly.IsFakeAssembly = true;
            mrAssembly.Name           = name;
            return(mrAssembly);
        }
        public MrCustomAttribute(CustomAttributeHandle handle, MrType targetType, MrAssembly assembly)
        {
            Handle     = handle;
            Assembly   = assembly;
            TargetType = targetType;

            CustomAttribute = assembly.Reader.GetCustomAttribute(handle);
        }
 internal static MrType CreateFromGenericParameterHandle(
     GenericParameterHandle handle,
     MrAssembly assembly,
     int arrayRank    = 0,
     bool isReference = false,
     bool isPointer   = false)
 {
     return(new MrType(handle, assembly)
     {
         ArrayRank = arrayRank,
         IsReference = isReference,
         IsPointer = isPointer
     });
 }
        private MrType(string fakeFullName, MrAssembly assembly)
        {
            this.Assembly = assembly;

            var index = fakeFullName.LastIndexOf('.');

            if (index == -1)
            {
                _fakeName = fakeFullName;
            }
            else
            {
                _fakeNamespace = fakeFullName.Substring(0, index);
                _fakeName      = fakeFullName.Substring(index + 1);
            }

            Debug.WriteLine($"Faking {_fakeName}");
        }
Esempio n. 7
0
        static public MrAssembly Create(MetadataReader reader, string location, MrLoadContext loadContext)
        {
            var mrAssembly = new MrAssembly(reader, location, loadContext);

            return(mrAssembly);
        }
 static public MrType AsMrType(this PrimitiveTypeCode typeCode, MrAssembly assembly)
 {
     return(MrType.CreatePrimitiveType(typeCode));
 }
 static public MrType AsMrType(this TypeDefinitionHandle handle, MrAssembly assembly)
 {
     return(MrType.CreateFromTypeDefinition(handle, assembly));
 }
 // Create a placeholder type that was referenced but wasn't in any of the loaded assemblies
 static internal MrType CreateFakeType(string name, MrAssembly assembly)
 {
     return(new MrType(name, assembly));
 }
 private MrType(TypeDefinitionHandle typeDefinitionHandle, MrAssembly assembly)
 {
     TypeDefinitionHandle = typeDefinitionHandle;
     Assembly             = assembly;
     TypeDefinition       = Assembly.Reader.GetTypeDefinition(typeDefinitionHandle);
 }
        /// <summary>
        /// Create a type from the type table.
        /// </summary>
        static internal MrType CreateFromTypeDefinition(TypeDefinitionHandle typeDefinitionHandle, MrAssembly assembly)
        {
            var type = assembly.GetFromCacheOrCreate(
                typeDefinitionHandle,
                () => new MrType(typeDefinitionHandle, assembly));

            Debug.Assert(type == assembly.GetFromCacheOrCreate(typeDefinitionHandle, null));

            return(type);
        }
 private MrType(GenericParameterHandle handle, MrAssembly assembly)
 {
     Assembly = assembly;
     GenericParameterHandle = handle;
 }
Esempio n. 14
0
 /// <summary>
 /// Converts a StringHandle to a String
 /// </summary>
 internal static string AsString(this StringHandle stringHandle, MrAssembly assembly)
 {
     return(assembly.Reader.GetString(stringHandle));
 }
Esempio n. 15
0
 public DisassemblingTypeProvider(MrAssembly assembly)
 {
     Assembly = assembly;
 }
 public CustomAttributeTypeProvider(MrAssembly assembly) : base(assembly)
 {
 }