Esempio n. 1
0
        private static object DeserializeArray(XmlReader xmlReader)
        {
            string startingElementName = xmlReader.Name;
            xmlReader.Read();
            string arrayType = xmlReader.Name;

            ArrayList array = new ArrayList();
            Type returnType = null;

            while (xmlReader.Name != startingElementName)
            {
                string tempValue = xmlReader.ReadElementString();

                switch (arrayType)
                {
                    case "boolean":
                        returnType = returnType ?? typeof(bool);
                        array.Add(tempValue == "true");
                        break;

                    // TODO: this is not an array but a base64 encoded string
                    //case "byte":
                    //    //returnType = returnType ?? typeof(bool);
                    //    //return Convert.FromBase64String(tempValue);
                    //    //throw new Exception("Should never reach this");
                    //    break;

                    case "byte":
                        returnType = returnType ?? typeof(sbyte);
                        array.Add(Convert.ToSByte(tempValue));
                        break;

                    case "char":
                        returnType = returnType ?? typeof(char);
                        array.Add(Convert.ToChar(Convert.ToByte(tempValue)));
                        break;

                    case "dateTime":
                        returnType = returnType ?? typeof(DateTime);
                        array.Add(GetDateTimeFromString(tempValue));
                        break;

                    case "double":
                        returnType = returnType ?? typeof(double);
                        array.Add(Convert.ToDouble(tempValue));
                        break;

                    case "guid":
                        returnType = returnType ?? typeof(Guid);
                        array.Add(GetGuidFromString(tempValue));
                        break;

                    case "short":
                        returnType = returnType ?? typeof(short);
                        array.Add(Convert.ToInt16(tempValue));
                        break;
                    case "unsignedShort":
                        returnType = returnType ?? typeof(ushort);
                        array.Add(Convert.ToUInt16(tempValue));
                        break;

                    case "int":
                        returnType = returnType ?? typeof(int);
                        array.Add(Convert.ToInt32(tempValue));
                        break;
                    case "unsignedInt":
                        returnType = returnType ?? typeof(uint);
                        array.Add(Convert.ToUInt32(tempValue));
                        break;

                    case "long":
                        returnType = returnType ?? typeof(long);
                        array.Add(Convert.ToInt64(tempValue));
                        break;
                    case "unsignedLong":
                        returnType = returnType ?? typeof(ulong);
                        array.Add(Convert.ToUInt64(tempValue));
                        break;

                    case "float":
                        returnType = returnType ?? typeof(float);
                        array.Add((Single)Convert.ToDouble(tempValue));
                        break;

                    case "string":
                        returnType = returnType ?? typeof(string);
                        array.Add(tempValue);
                        break;

                    default:
                        returnType = returnType ?? typeof(object);
                        break;
                }
            }

            return array.ToArray(returnType);
        }