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); }
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; })); }
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)); }
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); }
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); }
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; }
internal ModuleDefinition() { this.MetadataSystem = new MetadataSystem(); this.token = new MetadataToken(TokenType.Module, 1); }
public TypeDefinition GetMethodDeclaringType(uint method_rid) { return(MetadataSystem.BinaryRangeSearch(this.Types, method_rid, false)); }
public TypeDefinition GetFieldDeclaringType(uint field_rid) { return(MetadataSystem.BinaryRangeSearch(this.Types, field_rid, true)); }