예제 #1
0
        private static TypeReference CreateReference(TypeParser.Type type_info, ModuleDefinition module, IMetadataScope scope)
        {
            string @namespace;
            string name;

            TypeParser.SplitFullName(type_info.type_fullname, out @namespace, out name);
            TypeReference typeReference = new TypeReference(@namespace, name, module, scope);

            MetadataSystem.TryProcessPrimitiveTypeReference(typeReference);
            TypeParser.AdjustGenericParameters(typeReference);
            string[] nested_names = type_info.nested_names;
            if (nested_names.IsNullOrEmpty <string>())
            {
                return(typeReference);
            }
            for (int i = 0; i < nested_names.Length; i++)
            {
                typeReference = new TypeReference(string.Empty, nested_names[i], module, null)
                {
                    DeclaringType = typeReference
                };
                TypeParser.AdjustGenericParameters(typeReference);
            }
            return(typeReference);
        }
예제 #2
0
파일: TypeSystem.cs 프로젝트: 2173/cshotfix
            private TypeReference LookupTypeDefinition(string @namespace, string name)
            {
                MetadataSystem metadataSystem = this.module.MetadataSystem;

                if (metadataSystem.Types == null)
                {
                    TypeSystem.CoreTypeSystem.Initialize(this.module.Types);
                }
                return(this.module.Read <Row <string, string>, TypeDefinition>(new Row <string, string>(@namespace, name), delegate(Row <string, string> row, MetadataReader reader)
                {
                    TypeDefinition[] types = reader.metadata.Types;
                    for (int i = 0; i < types.Length; i++)
                    {
                        if (types[i] == null)
                        {
                            types[i] = reader.GetTypeDefinition((uint)(i + 1));
                        }
                        TypeDefinition typeDefinition = types[i];
                        if (typeDefinition.Name == row.Col2 && typeDefinition.Namespace == row.Col1)
                        {
                            return typeDefinition;
                        }
                    }
                    return null;
                }));
            }
예제 #3
0
 private static bool TryGetPrimitiveData(TypeReference type, out Row <ElementType, bool> primitive_data)
 {
     if (MetadataSystem.primitive_value_types == null)
     {
         MetadataSystem.InitializePrimitives();
     }
     return(MetadataSystem.primitive_value_types.TryGetValue(type.Name, out primitive_data));
 }
예제 #4
0
        public static bool TryGetPrimitiveElementType(TypeDefinition type, out ElementType etype)
        {
            etype = ElementType.None;
            if (type.Namespace != "System")
            {
                return(false);
            }
            Row <ElementType, bool> row;

            if (MetadataSystem.TryGetPrimitiveData(type, out row) && row.Col1.IsPrimitive())
            {
                etype = row.Col1;
                return(true);
            }
            return(false);
        }
예제 #5
0
        private TypeReference ImportType(TypeReference type, ImportGenericContext context)
        {
            if (type.IsTypeSpecification())
            {
                return(this.ImportTypeSpecification(type, context));
            }
            TypeReference typeReference = new TypeReference(type.Namespace, type.Name, this.module, this.ImportScope(type.Scope), type.IsValueType);

            MetadataSystem.TryProcessPrimitiveTypeReference(typeReference);
            if (type.IsNested)
            {
                typeReference.DeclaringType = this.ImportType(type.DeclaringType, context);
            }
            if (type.HasGenericParameters)
            {
                MetadataImporter.ImportGenericParameters(typeReference, type);
            }
            return(typeReference);
        }
예제 #6
0
        public static void TryProcessPrimitiveTypeReference(TypeReference type)
        {
            if (type.Namespace != "System")
            {
                return;
            }
            IMetadataScope scope = type.scope;

            if (scope == null || scope.MetadataScopeType != MetadataScopeType.AssemblyNameReference)
            {
                return;
            }
            Row <ElementType, bool> row;

            if (!MetadataSystem.TryGetPrimitiveData(type, out row))
            {
                return;
            }
            type.etype       = row.Col1;
            type.IsValueType = row.Col2;
        }
예제 #7
0
 internal ModuleDefinition()
 {
     this.MetadataSystem = new MetadataSystem();
     this.token          = new MetadataToken(TokenType.Module, 1);
 }
예제 #8
0
 public TypeDefinition GetMethodDeclaringType(uint method_rid)
 {
     return(MetadataSystem.BinaryRangeSearch(this.Types, method_rid, false));
 }
예제 #9
0
 public TypeDefinition GetFieldDeclaringType(uint field_rid)
 {
     return(MetadataSystem.BinaryRangeSearch(this.Types, field_rid, true));
 }