Example #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);
        }
Example #2
0
        private static bool TryGetDefinition(ModuleDefinition module, TypeParser.Type type_info, out TypeReference type)
        {
            type = null;
            if (!TypeParser.TryCurrentModule(module, type_info))
            {
                return(false);
            }
            TypeDefinition typeDefinition = module.GetType(type_info.type_fullname);

            if (typeDefinition == null)
            {
                return(false);
            }
            string[] nested_names = type_info.nested_names;
            if (!nested_names.IsNullOrEmpty <string>())
            {
                for (int i = 0; i < nested_names.Length; i++)
                {
                    TypeDefinition nestedType = typeDefinition.GetNestedType(nested_names[i]);
                    if (nestedType == null)
                    {
                        return(false);
                    }
                    typeDefinition = nestedType;
                }
            }
            type = typeDefinition;
            return(true);
        }
Example #3
0
        private static TypeReference GetTypeReference(ModuleDefinition module, TypeParser.Type type_info)
        {
            TypeReference type;

            if (!TypeParser.TryGetDefinition(module, type_info, out type))
            {
                type = TypeParser.CreateReference(type_info, module, TypeParser.GetMetadataScope(module, type_info));
            }
            return(TypeParser.CreateSpecs(type, type_info));
        }
Example #4
0
        private static IMetadataScope GetMetadataScope(ModuleDefinition module, TypeParser.Type type_info)
        {
            if (string.IsNullOrEmpty(type_info.assembly))
            {
                return(module.TypeSystem.CoreLibrary);
            }
            AssemblyNameReference assemblyNameReference = AssemblyNameReference.Parse(type_info.assembly);
            AssemblyNameReference result;

            if (!module.TryGetAssemblyNameReference(assemblyNameReference, out result))
            {
                return(assemblyNameReference);
            }
            return(result);
        }
Example #5
0
        private static bool TryGetArity(TypeParser.Type type)
        {
            int num = 0;

            TypeParser.TryAddArity(type.type_fullname, ref num);
            string[] nested_names = type.nested_names;
            if (!nested_names.IsNullOrEmpty <string>())
            {
                for (int i = 0; i < nested_names.Length; i++)
                {
                    TypeParser.TryAddArity(nested_names[i], ref num);
                }
            }
            type.arity = num;
            return(num > 0);
        }
Example #6
0
 private TypeParser.Type ParseType(bool fq_name)
 {
     TypeParser.Type type = new TypeParser.Type();
     type.type_fullname = this.ParsePart();
     type.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);
 }
Example #7
0
        private static TypeReference CreateSpecs(TypeReference type, TypeParser.Type type_info)
        {
            type = TypeParser.TryCreateGenericInstanceType(type, type_info);
            int[] specs = type_info.specs;
            if (specs.IsNullOrEmpty <int>())
            {
                return(type);
            }
            for (int i = 0; i < specs.Length; i++)
            {
                switch (specs[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 < specs[i]; j++)
                    {
                        arrayType.Dimensions.Add(default(ArrayDimension));
                    }
                    type = arrayType;
                    break;
                }
                }
            }
            return(type);
        }
Example #8
0
 private static bool TryCurrentModule(ModuleDefinition module, TypeParser.Type type_info)
 {
     return(string.IsNullOrEmpty(type_info.assembly) || (module.assembly != null && module.assembly.Name.FullName == type_info.assembly));
 }
Example #9
0
        private static TypeReference TryCreateGenericInstanceType(TypeReference type, TypeParser.Type type_info)
        {
            TypeParser.Type[] generic_arguments = type_info.generic_arguments;
            if (generic_arguments.IsNullOrEmpty <TypeParser.Type>())
            {
                return(type);
            }
            GenericInstanceType        genericInstanceType = new GenericInstanceType(type);
            Collection <TypeReference> genericArguments    = genericInstanceType.GenericArguments;

            for (int i = 0; i < generic_arguments.Length; i++)
            {
                genericArguments.Add(TypeParser.GetTypeReference(type.Module, generic_arguments[i]));
            }
            return(genericInstanceType);
        }