Exemple #1
0
 public static TypeData GetPrimitiveTypeData(string typeName)
 {
     return(TypeTranslator.GetPrimitiveTypeData(typeName, false));
 }
Exemple #2
0
        public static TypeData GetTypeData(Type runtimeType, string xmlDataType)
        {
            Type type = runtimeType;
            bool flag = false;

            if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable <>))
            {
                flag = true;
                type = type.GetGenericArguments()[0];
                TypeData typeData = TypeTranslator.GetTypeData(type);
                if (typeData != null)
                {
                    TypeData typeData2 = (TypeData)TypeTranslator.nullableTypes[typeData.XmlType];
                    if (typeData2 == null)
                    {
                        typeData2            = new TypeData(type, typeData.XmlType, false);
                        typeData2.IsNullable = true;
                        TypeTranslator.nullableTypes[typeData.XmlType] = typeData2;
                    }
                    return(typeData2);
                }
            }
            if (xmlDataType != null && xmlDataType.Length != 0)
            {
                TypeData primitiveTypeData = TypeTranslator.GetPrimitiveTypeData(xmlDataType);
                if (!type.IsArray || type == primitiveTypeData.Type)
                {
                    return(primitiveTypeData);
                }
                TypeData typeData3 = (TypeData)TypeTranslator.primitiveArrayTypes[xmlDataType];
                if (typeData3 != null)
                {
                    return(typeData3);
                }
                if (primitiveTypeData.Type == type.GetElementType())
                {
                    typeData3 = new TypeData(type, TypeTranslator.GetArrayName(primitiveTypeData.XmlType), false);
                    TypeTranslator.primitiveArrayTypes[xmlDataType] = typeData3;
                    return(typeData3);
                }
                throw new InvalidOperationException(string.Concat(new object[]
                {
                    "Cannot convert values of type '",
                    type.GetElementType(),
                    "' to '",
                    xmlDataType,
                    "'"
                }));
            }
            else
            {
                TypeData typeData4 = TypeTranslator.nameCache[runtimeType] as TypeData;
                if (typeData4 != null)
                {
                    return(typeData4);
                }
                string text;
                if (type.IsArray)
                {
                    string xmlType = TypeTranslator.GetTypeData(type.GetElementType()).XmlType;
                    text = TypeTranslator.GetArrayName(xmlType);
                }
                else if (type.IsGenericType && !type.IsGenericTypeDefinition)
                {
                    text = XmlConvert.EncodeLocalName(type.Name.Substring(0, type.Name.IndexOf('`'))) + "Of";
                    foreach (Type type2 in type.GetGenericArguments())
                    {
                        text += ((!type2.IsArray && !type2.IsGenericType) ? CodeIdentifier.MakePascal(XmlConvert.EncodeLocalName(type2.Name)) : TypeTranslator.GetTypeData(type2).XmlType);
                    }
                }
                else
                {
                    text = XmlConvert.EncodeLocalName(type.Name);
                }
                typeData4 = new TypeData(type, text, false);
                if (flag)
                {
                    typeData4.IsNullable = true;
                }
                TypeTranslator.nameCache[runtimeType] = typeData4;
                return(typeData4);
            }
        }
        bool ReadList(out object resultList)
        {
            string arrayTypeAttr = Reader.GetAttribute(arrayType, soapNS);

            if (arrayTypeAttr == null)
            {
                arrayTypeAttr = Reader.GetAttribute(arrayType, wsdlNS);
            }

            XmlQualifiedName qn = ToXmlQualifiedName(arrayTypeAttr);
            int    i            = qn.Name.LastIndexOf('[');
            string dim          = qn.Name.Substring(i);
            string itemType     = qn.Name.Substring(0, i);
            int    count        = Int32.Parse(dim.Substring(1, dim.Length - 2), CultureInfo.InvariantCulture);

            Array list;

            i = itemType.IndexOf('['); if (i == -1)
            {
                i = itemType.Length;
            }
            string baseType = itemType.Substring(0, i);
            string arrayTypeName;

            if (qn.Namespace == w3SchemaNS)
            {
                arrayTypeName = TypeTranslator.GetPrimitiveTypeData(baseType).Type.FullName + itemType.Substring(i);
            }
            else
            {
                WriteCallbackInfo info = GetCallbackInfo(new XmlQualifiedName(baseType, qn.Namespace));
                arrayTypeName = info.Type.FullName + itemType.Substring(i) + ", " + info.Type.Assembly.FullName;
            }

            list = Array.CreateInstance(Type.GetType(arrayTypeName), count);

            bool listComplete = true;

            if (Reader.IsEmptyElement)
            {
                readCount++;
                Reader.Skip();
            }
            else
            {
                Reader.ReadStartElement();
                for (int n = 0; n < count; n++)
                {
                    whileIterationCount++;
                    readCount++;
                    Reader.MoveToContent();
                    string id;
                    object item = ReadReferencingElement(itemType, qn.Namespace, out id);
                    if (id == null)
                    {
                        list.SetValue(item, n);
                    }
                    else
                    {
                        AddFixup(new CollectionItemFixup(list, n, id));
                        listComplete = false;
                    }
                }
                whileIterationCount = 0;
                Reader.ReadEndElement();
            }

            resultList = list;
            return(listComplete);
        }