private static TypeReference CreateReference(TypeParser.Type type_info, ModuleDefinition module, IMetadataScope scope) { string str; string str1; TypeParser.SplitFullName(type_info.type_fullname, out str, out str1); TypeReference typeReference = new TypeReference(str, str1, module, scope); MetadataSystem.TryProcessPrimitiveTypeReference(typeReference); TypeParser.AdjustGenericParameters(typeReference); string[] nestedNames = type_info.nested_names; if (nestedNames.IsNullOrEmpty <string>()) { return(typeReference); } for (int i = 0; i < (int)nestedNames.Length; i++) { typeReference = new TypeReference(string.Empty, nestedNames[i], module, null) { DeclaringType = typeReference }; TypeParser.AdjustGenericParameters(typeReference); } return(typeReference); }
private static IMetadataScope GetMetadataScope(ModuleDefinition module, TypeParser.Type type_info) { if (string.IsNullOrEmpty(type_info.assembly)) { return(module.TypeSystem.Corlib); } return(TypeParser.MatchReference(module, AssemblyNameReference.Parse(type_info.assembly))); }
private static TypeReference GetTypeReference(ModuleDefinition module, TypeParser.Type type_info) { TypeReference typeReference; if (!TypeParser.TryGetDefinition(module, type_info, out typeReference)) { typeReference = TypeParser.CreateReference(type_info, module, TypeParser.GetMetadataScope(module, type_info)); } return(TypeParser.CreateSpecs(typeReference, type_info)); }
private static bool TryCurrentModule(ModuleDefinition module, TypeParser.Type type_info) { if (string.IsNullOrEmpty(type_info.assembly)) { return(true); } if (module.assembly != null && module.assembly.Name.FullName == type_info.assembly) { return(true); } return(false); }
private static bool TryGetArity(TypeParser.Type type) { int num = 0; TypeParser.TryAddArity(type.type_fullname, ref num); string[] nestedNames = type.nested_names; if (!nestedNames.IsNullOrEmpty <string>()) { for (int i = 0; i < (int)nestedNames.Length; i++) { TypeParser.TryAddArity(nestedNames[i], ref num); } } type.arity = num; return(num > 0); }
private static TypeReference CreateSpecs(TypeReference type, TypeParser.Type type_info) { type = TypeParser.TryCreateGenericInstanceType(type, type_info); int[] typeInfo = type_info.specs; if (typeInfo.IsNullOrEmpty <int>()) { return(type); } for (int i = 0; i < (int)typeInfo.Length; i++) { switch (typeInfo[i]) { case -3: { type = new ArrayType(type); break; } case -2: { type = new ByReferenceType(type); break; } case -1: { type = new PointerType(type); break; } default: { ArrayType arrayType = new ArrayType(type); arrayType.Dimensions.Clear(); for (int j = 0; j < typeInfo[i]; j++) { arrayType.Dimensions.Add(new ArrayDimension()); } type = arrayType; break; } } } return(type); }
private TypeParser.Type ParseType(bool fq_name) { TypeParser.Type type = new TypeParser.Type() { type_fullname = this.ParsePart(), nested_names = this.ParseNestedNames() }; if (TypeParser.TryGetArity(type)) { type.generic_arguments = this.ParseGenericArguments(type.arity); } type.specs = this.ParseSpecs(); if (fq_name) { type.assembly = this.ParseAssemblyName(); } return(type); }
private static bool TryGetDefinition(ModuleDefinition module, TypeParser.Type type_info, out TypeReference type) { type = null; if (!TypeParser.TryCurrentModule(module, type_info)) { return(false); } TypeDefinition nestedType = module.GetType(type_info.type_fullname); if (nestedType == null) { return(false); } string[] nestedNames = type_info.nested_names; if (!nestedNames.IsNullOrEmpty <string>()) { for (int i = 0; i < (int)nestedNames.Length; i++) { nestedType = nestedType.GetNestedType(nestedNames[i]); } } type = nestedType; return(true); }
private static TypeReference TryCreateGenericInstanceType(TypeReference type, TypeParser.Type type_info) { TypeParser.Type[] genericArguments = type_info.generic_arguments; if (genericArguments.IsNullOrEmpty <TypeParser.Type>()) { return(type); } GenericInstanceType genericInstanceType = new GenericInstanceType(type); Collection <TypeReference> typeReferences = genericInstanceType.GenericArguments; for (int i = 0; i < (int)genericArguments.Length; i++) { typeReferences.Add(TypeParser.GetTypeReference(type.Module, genericArguments[i])); } return(genericInstanceType); }