GetTypeDesc() private method

private GetTypeDesc ( Type type ) : TypeDesc
type System.Type
return TypeDesc
Example #1
0
        private string WriteTypeInfo(TypeScope scope, TypeDesc typeDesc, Type type)
        {
            this.InitTheFirstTime();
            string cSharpName = typeDesc.CSharpName;
            string str2       = (string)this.reflectionVariables[cSharpName];

            if (str2 == null)
            {
                if (type.IsArray)
                {
                    str2 = this.GenerateVariableName("array", typeDesc.CSharpName);
                    TypeDesc arrayElementTypeDesc = typeDesc.ArrayElementTypeDesc;
                    if (arrayElementTypeDesc.UseReflection)
                    {
                        string str3 = this.WriteTypeInfo(scope, arrayElementTypeDesc, scope.GetTypeFromTypeDesc(arrayElementTypeDesc));
                        this.writer.WriteLine("static " + typeof(Type).FullName + " " + str2 + " = " + str3 + ".MakeArrayType();");
                    }
                    else
                    {
                        string str4 = this.WriteAssemblyInfo(type);
                        this.writer.Write("static " + typeof(Type).FullName + " " + str2 + " = " + str4 + ".GetType(");
                        this.WriteQuotedCSharpString(type.FullName);
                        this.writer.WriteLine(");");
                    }
                }
                else
                {
                    str2 = this.GenerateVariableName("type", typeDesc.CSharpName);
                    Type underlyingType = Nullable.GetUnderlyingType(type);
                    if (underlyingType != null)
                    {
                        string str5 = this.WriteTypeInfo(scope, scope.GetTypeDesc(underlyingType), underlyingType);
                        this.writer.WriteLine("static " + typeof(Type).FullName + " " + str2 + " = typeof(System.Nullable<>).MakeGenericType(new " + typeof(Type).FullName + "[] {" + str5 + "});");
                    }
                    else
                    {
                        string str6 = this.WriteAssemblyInfo(type);
                        this.writer.Write("static " + typeof(Type).FullName + " " + str2 + " = " + str6 + ".GetType(");
                        this.WriteQuotedCSharpString(type.FullName);
                        this.writer.WriteLine(");");
                    }
                }
                this.reflectionVariables.Add(cSharpName, str2);
                TypeMapping typeMappingFromTypeDesc = scope.GetTypeMappingFromTypeDesc(typeDesc);
                if (typeMappingFromTypeDesc != null)
                {
                    this.WriteMappingInfo(typeMappingFromTypeDesc, str2, type);
                }
                if (typeDesc.IsCollection || typeDesc.IsEnumerable)
                {
                    TypeDesc desc2 = typeDesc.ArrayElementTypeDesc;
                    if (desc2.UseReflection)
                    {
                        this.WriteTypeInfo(scope, desc2, scope.GetTypeFromTypeDesc(desc2));
                    }
                    this.WriteCollectionInfo(str2, typeDesc, type);
                }
            }
            return(str2);
        }
Example #2
0
 internal void WriteReflectionInit(TypeScope scope)
 {
     foreach (Type type in scope.Types)
     {
         TypeDesc typeDesc = scope.GetTypeDesc(type);
         if (typeDesc.UseReflection)
         {
             this.WriteTypeInfo(scope, typeDesc, type);
         }
     }
 }
        TypeMapping ImportTypeMapping(TypeModel model, string dataType)
        {
            if (dataType.Length > 0)
            {
                if (!model.TypeDesc.IsPrimitive)
                {
                    throw new InvalidOperationException(Res.GetString(Res.XmlInvalidDataTypeUsage, dataType, "SoapElementAttribute.DataType"));
                }
                TypeDesc td = typeScope.GetTypeDesc(new XmlQualifiedName(dataType, XmlSchema.Namespace));
                if (td == null)
                {
                    throw new InvalidOperationException(Res.GetString(Res.XmlInvalidXsdDataType, dataType, "SoapElementAttribute.DataType", new XmlQualifiedName(dataType, XmlSchema.Namespace).ToString()));
                }
                if (model.TypeDesc.FullName != td.FullName)
                {
                    throw new InvalidOperationException(Res.GetString(Res.XmlDataTypeMismatch, dataType, "SoapElementAttribute.DataType", model.TypeDesc.FullName));
                }
            }

            SoapAttributes a = GetAttributes(model.Type);

            if ((a.SoapFlags & ~SoapAttributeFlags.Type) != 0)
            {
                throw new InvalidOperationException(Res.GetString(Res.XmlInvalidTypeAttributes, model.Type.FullName));
            }

            switch (model.TypeDesc.Kind)
            {
            case TypeKind.Enum:
                return(ImportEnumMapping((EnumModel)model));

            case TypeKind.Primitive:
                return(ImportPrimitiveMapping((PrimitiveModel)model, dataType));

            case TypeKind.Array:
            case TypeKind.Collection:
            case TypeKind.Enumerable:
                return(ImportArrayLikeMapping((ArrayModel)model));

            case TypeKind.Root:
            case TypeKind.Class:
            case TypeKind.Struct:
            case TypeKind.Interface:
                return(ImportStructLikeMapping((StructModel)model));

            default:
                throw new NotSupportedException(Res.GetString(Res.XmlUnsupportedSoapTypeKind, model.TypeDesc.FullName));
            }
        }
Example #4
0
        public TypeModel GetTypeModel(Type type)
        {
            TypeModel model = (TypeModel)models[type];

            if (model != null)
            {
                return(model);
            }
            TypeDesc typeDesc = typeScope.GetTypeDesc(type);

            switch (typeDesc.Kind)
            {
            case TypeKind.Enum:
                model = new EnumModel(type, typeDesc, this);
                break;

            case TypeKind.Primitive:
                model = new PrimitiveModel(type, typeDesc, this);
                break;

            case TypeKind.Array:
            case TypeKind.Collection:
            case TypeKind.Enumerable:
                model = new ArrayModel(type, typeDesc, this);
                break;

            case TypeKind.Root:
            case TypeKind.Class:
            case TypeKind.Struct:
            case TypeKind.Interface:
                model = new StructModel(type, typeDesc, this);
                break;

            default:
                if (!typeDesc.IsSpecial)
                {
                    throw new NotSupportedException(Res.GetString(Res.XmlUnsupportedTypeKind, type.FullName));
                }
                model = new SpecialModel(type, typeDesc, this);
                break;
            }

            models.Add(type, model);
            return(model);
        }
Example #5
0
        internal TypeModel GetTypeModel(Type type, bool directReference)
        {
            TypeModel?model;

            if (_models.TryGetValue(type, out model))
            {
                return(model);
            }
            TypeDesc typeDesc = _typeScope.GetTypeDesc(type, null, directReference);

            switch (typeDesc.Kind)
            {
            case TypeKind.Enum:
                model = new EnumModel(type, typeDesc, this);
                break;

            case TypeKind.Primitive:
                model = new PrimitiveModel(type, typeDesc, this);
                break;

            case TypeKind.Array:
            case TypeKind.Collection:
            case TypeKind.Enumerable:
                model = new ArrayModel(type, typeDesc, this);
                break;

            case TypeKind.Root:
            case TypeKind.Class:
            case TypeKind.Struct:
                model = new StructModel(type, typeDesc, this);
                break;

            default:
                if (!typeDesc.IsSpecial)
                {
                    throw new NotSupportedException(SR.Format(SR.XmlUnsupportedTypeKind, type.FullName));
                }
                model = new SpecialModel(type, typeDesc, this);
                break;
            }

            _models.Add(type, model);
            return(model);
        }
        string WriteTypeInfo(TypeScope scope, TypeDesc typeDesc, Type type){
            InitTheFirstTime();
            string typeFullName = typeDesc.CSharpName;
            string typeVariable = (string)reflectionVariables[typeFullName];
            if (typeVariable != null)
                return typeVariable;

            if (type.IsArray)
            {
                typeVariable = GenerateVariableName("array", typeDesc.CSharpName);
                TypeDesc elementTypeDesc = typeDesc.ArrayElementTypeDesc;
                if (elementTypeDesc.UseReflection)
                {
                    string elementTypeVariable = WriteTypeInfo(scope, elementTypeDesc, scope.GetTypeFromTypeDesc(elementTypeDesc));
                    writer.WriteLine("static "+typeof(Type).FullName+" "+typeVariable +" = " + elementTypeVariable + ".MakeArrayType();");
                }
                else
                {
                    string assemblyVariable = WriteAssemblyInfo(type);
                    writer.Write("static "+typeof(Type).FullName+" "+typeVariable +" = "+assemblyVariable+".GetType(");
                    WriteQuotedCSharpString(type.FullName);
                    writer.WriteLine(");");
                }
            }
            else
            {
                typeVariable = GenerateVariableName("type", typeDesc.CSharpName);

                Type parameterType = Nullable.GetUnderlyingType(type);
                if (parameterType != null)
                {
                    string parameterTypeVariable = WriteTypeInfo(scope, scope.GetTypeDesc(parameterType), parameterType);
                    writer.WriteLine("static "+typeof(Type).FullName+" "+typeVariable +" = typeof(System.Nullable<>).MakeGenericType(new " + typeof(Type).FullName + "[] {"+parameterTypeVariable+"});");
                }
                else
                {
                    string assemblyVariable = WriteAssemblyInfo(type);
                    writer.Write("static "+typeof(Type).FullName+" "+typeVariable +" = "+assemblyVariable+".GetType(");
                    WriteQuotedCSharpString(type.FullName);
                    writer.WriteLine(");");
                }
            }
            
            reflectionVariables.Add(typeFullName, typeVariable);

            TypeMapping mapping = scope.GetTypeMappingFromTypeDesc(typeDesc);
            if (mapping != null)
                WriteMappingInfo(mapping, typeVariable, type);
            if (typeDesc.IsCollection || typeDesc.IsEnumerable){// Arrays use the generic item_Array
                TypeDesc elementTypeDesc = typeDesc.ArrayElementTypeDesc;
                if (elementTypeDesc.UseReflection)
                    WriteTypeInfo(scope, elementTypeDesc, scope.GetTypeFromTypeDesc(elementTypeDesc));
                WriteCollectionInfo(typeVariable, typeDesc, type);
            }
            return typeVariable;
        }
 internal void WriteReflectionInit(TypeScope scope){
     foreach (Type type in scope.Types) {
         TypeDesc typeDesc = scope.GetTypeDesc(type);
         if (typeDesc.UseReflection)
             WriteTypeInfo(scope, typeDesc, type);
     }
 }
Example #8
0
        private TypeMapping ImportTypeMapping(TypeModel model, string dataType, RecursionLimiter limiter)
        {
            if (dataType.Length > 0)
            {
                if (!model.TypeDesc.IsPrimitive)
                {
                    throw new InvalidOperationException(SR.Format(SR.XmlInvalidDataTypeUsage, dataType, "SoapElementAttribute.DataType"));
                }
                TypeDesc td = _typeScope.GetTypeDesc(dataType, XmlSchema.Namespace);
                if (td == null)
                {
                    throw new InvalidOperationException(SR.Format(SR.XmlInvalidXsdDataType, dataType, "SoapElementAttribute.DataType", new XmlQualifiedName(dataType, XmlSchema.Namespace).ToString()));
                }
                if (model.TypeDesc.FullName != td.FullName)
                {
                    throw new InvalidOperationException(SR.Format(SR.XmlDataTypeMismatch, dataType, "SoapElementAttribute.DataType", model.TypeDesc.FullName));
                }
            }

            SoapAttributes a = GetAttributes(model.Type);

            if ((a.GetSoapFlags() & ~SoapAttributeFlags.Type) != 0)
            {
                throw new InvalidOperationException(SR.Format(SR.XmlInvalidTypeAttributes, model.Type.FullName));
            }

            switch (model.TypeDesc.Kind)
            {
            case TypeKind.Enum:
                return(ImportEnumMapping((EnumModel)model));

            case TypeKind.Primitive:
                return(ImportPrimitiveMapping((PrimitiveModel)model, dataType));

            case TypeKind.Array:
            case TypeKind.Collection:
            case TypeKind.Enumerable:
                return(ImportArrayLikeMapping((ArrayModel)model, limiter));

            case TypeKind.Root:
            case TypeKind.Class:
            case TypeKind.Struct:
                if (model.TypeDesc.IsOptionalValue)
                {
                    TypeDesc       baseTypeDesc   = model.TypeDesc.BaseTypeDesc;
                    SoapAttributes baseAttributes = GetAttributes(baseTypeDesc.Type);
                    string         typeNs         = _defaultNs;
                    if (baseAttributes.SoapType != null && baseAttributes.SoapType.Namespace != null)
                    {
                        typeNs = baseAttributes.SoapType.Namespace;
                    }
                    TypeDesc    valueTypeDesc = string.IsNullOrEmpty(dataType) ? model.TypeDesc.BaseTypeDesc : _typeScope.GetTypeDesc(dataType, XmlSchema.Namespace);
                    string      xsdTypeName   = string.IsNullOrEmpty(dataType) ? model.TypeDesc.BaseTypeDesc.Name : dataType;
                    TypeMapping baseMapping   = GetTypeMapping(xsdTypeName, typeNs, valueTypeDesc);
                    if (baseMapping == null)
                    {
                        baseMapping = ImportTypeMapping(_modelScope.GetTypeModel(baseTypeDesc.Type), dataType, limiter);
                    }
                    return(CreateNullableMapping(baseMapping, model.TypeDesc.Type));
                }
                else
                {
                    return(ImportStructLikeMapping((StructModel)model, limiter));
                }

            default:
                throw new NotSupportedException(SR.Format(SR.XmlUnsupportedSoapTypeKind, model.TypeDesc.FullName));
            }
        }
 internal void WriteReflectionInit(TypeScope scope)
 {
     foreach (Type type in scope.Types)
     {
         TypeDesc typeDesc = scope.GetTypeDesc(type);
     }
 }
        /// <include file='doc\SoapSchemaImporter.uex' path='docs/doc[@for="SoapSchemaImporter.ImportMembersMapping"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public XmlMembersMapping ImportMembersMapping(string name, string ns, SoapSchemaMember member)
        {
            TypeMapping typeMapping = ImportType(member.MemberType, true);

            if (!(typeMapping is StructMapping))
            {
                return(ImportMembersMapping(name, ns, new SoapSchemaMember[] { member }));
            }

            MembersMapping mapping = new MembersMapping();

            mapping.TypeDesc          = scope.GetTypeDesc(typeof(object[]));
            mapping.Members           = ((StructMapping)typeMapping).Members;
            mapping.HasWrapperElement = true;

            ElementAccessor accessor = new ElementAccessor();

            accessor.IsSoap     = true;
            accessor.Name       = Accessor.EscapeName(name, false);
            accessor.Namespace  = typeMapping.Namespace != null ? typeMapping.Namespace : ns;
            accessor.Mapping    = mapping;
            accessor.IsNullable = false;
            accessor.Form       = XmlSchemaForm.Qualified;

            return(new XmlMembersMapping(scope, accessor));
        }
 private string WriteTypeInfo(TypeScope scope, TypeDesc typeDesc, Type type)
 {
     this.InitTheFirstTime();
     string cSharpName = typeDesc.CSharpName;
     string str2 = (string) this.reflectionVariables[cSharpName];
     if (str2 == null)
     {
         if (type.IsArray)
         {
             str2 = this.GenerateVariableName("array", typeDesc.CSharpName);
             TypeDesc arrayElementTypeDesc = typeDesc.ArrayElementTypeDesc;
             if (arrayElementTypeDesc.UseReflection)
             {
                 string str3 = this.WriteTypeInfo(scope, arrayElementTypeDesc, scope.GetTypeFromTypeDesc(arrayElementTypeDesc));
                 this.writer.WriteLine("static " + typeof(Type).FullName + " " + str2 + " = " + str3 + ".MakeArrayType();");
             }
             else
             {
                 string str4 = this.WriteAssemblyInfo(type);
                 this.writer.Write("static " + typeof(Type).FullName + " " + str2 + " = " + str4 + ".GetType(");
                 this.WriteQuotedCSharpString(type.FullName);
                 this.writer.WriteLine(");");
             }
         }
         else
         {
             str2 = this.GenerateVariableName("type", typeDesc.CSharpName);
             Type underlyingType = Nullable.GetUnderlyingType(type);
             if (underlyingType != null)
             {
                 string str5 = this.WriteTypeInfo(scope, scope.GetTypeDesc(underlyingType), underlyingType);
                 this.writer.WriteLine("static " + typeof(Type).FullName + " " + str2 + " = typeof(System.Nullable<>).MakeGenericType(new " + typeof(Type).FullName + "[] {" + str5 + "});");
             }
             else
             {
                 string str6 = this.WriteAssemblyInfo(type);
                 this.writer.Write("static " + typeof(Type).FullName + " " + str2 + " = " + str6 + ".GetType(");
                 this.WriteQuotedCSharpString(type.FullName);
                 this.writer.WriteLine(");");
             }
         }
         this.reflectionVariables.Add(cSharpName, str2);
         TypeMapping typeMappingFromTypeDesc = scope.GetTypeMappingFromTypeDesc(typeDesc);
         if (typeMappingFromTypeDesc != null)
         {
             this.WriteMappingInfo(typeMappingFromTypeDesc, str2, type);
         }
         if (typeDesc.IsCollection || typeDesc.IsEnumerable)
         {
             TypeDesc desc2 = typeDesc.ArrayElementTypeDesc;
             if (desc2.UseReflection)
             {
                 this.WriteTypeInfo(scope, desc2, scope.GetTypeFromTypeDesc(desc2));
             }
             this.WriteCollectionInfo(str2, typeDesc, type);
         }
     }
     return str2;
 }