Example #1
0
        AssemblyNameReference ImportAssemblyName(AssemblyNameReference name)
        {
            AssemblyNameReference reference;

            if (TryGetAssemblyNameReference(name, out reference))
            {
                return(reference);
            }

            reference = new AssemblyNameReference(name.Name, name.Version)
            {
                Culture       = name.Culture,
                HashAlgorithm = name.HashAlgorithm,
            };

            var pk_token = !Mixin.IsNullOrEmpty(name.PublicKeyToken)
                ? new byte[name.PublicKeyToken.Length]
                : Empty <byte> .Array;

            if (pk_token.Length > 0)
            {
                Buffer.BlockCopy(name.PublicKeyToken, 0, pk_token, 0, pk_token.Length);
            }

            reference.PublicKeyToken = pk_token;

            module.AssemblyReferences.Add(reference);

            return(reference);
        }
Example #2
0
        static bool TryGetDefinition(ModuleDefinition module, Type type_info, out TypeReference type)
        {
            type = null;
            if (!TryCurrentModule(module, type_info))
            {
                return(false);
            }

            var typedef = module.GetType(type_info.type_fullname);

            if (typedef == null)
            {
                return(false);
            }

            var nested_names = type_info.nested_names;

            if (!Mixin.IsNullOrEmpty(nested_names))
            {
                for (int i = 0; i < nested_names.Length; i++)
                {
                    typedef = Mixin.GetNestedType(typedef, nested_names[i]);
                }
            }

            type = typedef;
            return(true);
        }
Example #3
0
        static TypeReference CreateReference(Type type_info, ModuleDefinition module, IMetadataScope scope)
        {
            string @namespace, name;

            SplitFullName(type_info.type_fullname, out @namespace, out name);

            var type = new TypeReference(@namespace, name, module, scope);

            MetadataSystem.TryProcessPrimitiveTypeReference(type);

            AdjustGenericParameters(type);

            var nested_names = type_info.nested_names;

            if (Mixin.IsNullOrEmpty(nested_names))
            {
                return(type);
            }

            for (int i = 0; i < nested_names.Length; i++)
            {
                type = new TypeReference(string.Empty, nested_names[i], module, null)
                {
                    DeclaringType = type,
                };

                AdjustGenericParameters(type);
            }

            return(type);
        }
Example #4
0
        static bool TryGetArity(Type type)
        {
            int arity = 0;

            TryAddArity(type.type_fullname, ref arity);

            var nested_names = type.nested_names;

            if (!Mixin.IsNullOrEmpty(nested_names))
            {
                for (int i = 0; i < nested_names.Length; i++)
                {
                    TryAddArity(nested_names[i], ref arity);
                }
            }

            type.arity = arity;
            return(arity > 0);
        }
Example #5
0
        static TypeReference TryCreateGenericInstanceType(TypeReference type, Type type_info)
        {
            var generic_arguments = type_info.generic_arguments;

            if (Mixin.IsNullOrEmpty(generic_arguments))
            {
                return(type);
            }

            var instance           = new GenericInstanceType(type);
            var instance_arguments = instance.GenericArguments;

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

            return(instance);
        }
Example #6
0
        static TypeReference CreateSpecs(TypeReference type, Type type_info)
        {
            type = TryCreateGenericInstanceType(type, type_info);

            var specs = type_info.specs;

            if (Mixin.IsNullOrEmpty(specs))
            {
                return(type);
            }

            for (int i = 0; i < specs.Length; i++)
            {
                switch (specs[i])
                {
                case Type.Ptr:
                    type = new PointerType(type);
                    break;

                case Type.ByRef:
                    type = new ByReferenceType(type);
                    break;

                case Type.SzArray:
                    type = new ArrayType(type);
                    break;

                default:
                    var array = new ArrayType(type);
                    array.Dimensions.Clear();

                    for (int j = 0; j < specs[i]; j++)
                    {
                        array.Dimensions.Add(new ArrayDimension());
                    }

                    type = array;
                    break;
                }
            }

            return(type);
        }