Ejemplo n.º 1
0
 public StructType(TypeWrapper type)
 {
     this.Type = type;
 }
        public TypeWrapper AddType(TypeReference type)
        {
            TypeWrapper wrapper;

            if (!this.types.TryGetType(type.FullName, out wrapper))
            {
                Mono.Cecil.TokenType tokenType = type.MetadataToken.TokenType;
                if (tokenType != Mono.Cecil.TokenType.TypeRef)
                {
                    if (tokenType != Mono.Cecil.TokenType.TypeDef)
                    {
                        if (tokenType != Mono.Cecil.TokenType.TypeSpec)
                        {
                            throw new NotSupportedException(string.Format("Metadata token type {0} is not supported.", type.MetadataToken.TokenType));
                        }
                        MetadataType metadataType = type.MetadataType;
                        if (metadataType != MetadataType.Array)
                        {
                            if (metadataType != MetadataType.GenericInstance)
                            {
                                throw new NotSupportedException(string.Format("Metadata type {0} is not supported.", type.MetadataType));
                            }
                        }
                        else
                        {
                            ArrayType type4 = (ArrayType)type;
                            wrapper = new TypeWrapper(this, type4);
                            this.types.Add(type.FullName, wrapper);
                            wrapper.BaseType = this.metadataContainer.AddType(this.metadataContainer.OperationContext.ArrayType);
                            return(wrapper);
                        }
                        GenericInstanceType type5 = (GenericInstanceType)type;
                        wrapper = new TypeWrapper(this, type5);
                        this.types.Add(type.FullName, wrapper);
                        TypeDefinition definition2 = type5.ElementType.Resolve();
                        TypeReference  baseType    = definition2.BaseType;
                        if (baseType != null)
                        {
                            if (baseType.IsGenericInstance)
                            {
                                GenericInstanceType type6 = (GenericInstanceType)baseType;
                                baseType = MetadataContainer.MakeGenericType(type5, type6);
                            }
                            wrapper.BaseType = this.metadataContainer.AddType(baseType);
                        }
                        if (definition2.HasInterfaces)
                        {
                            TypeWrapper[] wrapperArray2 = new TypeWrapper[definition2.Interfaces.Count];
                            for (int i = 0; i < wrapperArray2.Length; i++)
                            {
                                TypeReference reference2 = definition2.Interfaces[i];
                                if (reference2.IsGenericInstance)
                                {
                                    GenericInstanceType type7 = (GenericInstanceType)reference2;
                                    reference2 = MetadataContainer.MakeGenericType(type5, type7);
                                }
                                wrapperArray2[i] = this.metadataContainer.AddType(reference2);
                            }
                            wrapper.Interfaces = wrapperArray2;
                        }
                        wrapper.Methods = this.GetCallableMethods(wrapper, definition2, this.system);
                        return(wrapper);
                    }
                }
                else
                {
                    return(this.metadataContainer.GetAssembly(type.Resolve().Scope).AddType(type.Resolve()));
                }
                TypeDefinition definition = (TypeDefinition)type;
                wrapper = new TypeWrapper(this, definition);
                this.types.Add(type.FullName, wrapper);
                if (definition.BaseType != null)
                {
                    wrapper.BaseType = this.metadataContainer.AddType(definition.BaseType);
                }
                if (definition.DeclaringType != null)
                {
                    wrapper.DeclaringType = this.metadataContainer.AddType(definition.DeclaringType);
                }
                if (definition.HasInterfaces)
                {
                    TypeWrapper[] wrapperArray = new TypeWrapper[definition.Interfaces.Count];
                    for (int j = 0; j < wrapperArray.Length; j++)
                    {
                        wrapperArray[j] = this.metadataContainer.AddType(definition.Interfaces[j]);
                    }
                    wrapper.Interfaces = wrapperArray;
                }
                wrapper.Methods = this.GetCallableMethods(wrapper, definition, this.system);
                if (!this.system)
                {
                    wrapper.Fields = this.GetFields(definition);
                }
            }
            return(wrapper);
        }