Esempio n. 1
0
        public object FromXml(XStreamReader reader, UnmarshallingContext context)
        {
            int count = reader.NoOfChildren();

            // Use the actual data type we are deserializing to rather than inferring from xml metadata
            Type arrayType = context.currentTargetType;

            string arrayTypeName = reader.GetAttribute(ARRAY_TYPE);

            if (arrayTypeName != "")
            {
                arrayType = context.GetTypeFromOtherAssemblies(arrayTypeName);
            }

            if (arrayType.IsArray)
            {
                // Due to the way that the currentTargetType and the constructor works, we need to get the element type instead of the current type.
                //  This probably won't work well for arrays of arrays.
                arrayType = arrayType.GetElementType();
            }

            Array result = Array.CreateInstance(arrayType, count);

            if (count != 0)
            {
                reader.MoveDown();
                for (int i = 0; i < count; i++)
                {
                    result.SetValue(context.ConvertOriginal(), i);
                    reader.MoveNext();
                }
                reader.MoveUp();
            }
            return(result);
        }
        private static void GetValueObject(UnmarshallingContext context, ref object value, XStreamReader reader)
        {
            Type previousType = context.currentTargetType;
            Type valueType    = context.currentTargetType.GenericTypeArguments[1];

            string nodeName = reader.GetNodeName();

            context.currentTargetType = valueType;
            value = context.ConvertOriginal(valueType);

            context.currentTargetType = previousType;
        }
        private static void GetKeyObject(UnmarshallingContext context, ref object key, XStreamReader reader)
        {
            Type previousType = context.currentTargetType;
            Type keyType      = context.currentTargetType.GenericTypeArguments[0];

            string nodeName = reader.GetNodeName();

            context.currentTargetType = keyType;
            key = context.ConvertOriginal(keyType);

            context.currentTargetType = previousType;
        }
Esempio n. 4
0
 public object FromXml(XStreamReader reader, UnmarshallingContext context) {
     int count = reader.NoOfChildren();
     Array result = Array.CreateInstance(context.GetTypeFromOtherAssemblies(reader.GetAttribute(ARRAY_TYPE)), count);
     if (count != 0) {
         reader.MoveDown();
         for (int i = 0; i < count; i++) {
             result.SetValue(context.ConvertOriginal(), i);
             reader.MoveNext();
         }
         reader.MoveUp();
     }
     return result;
 }
        private static void GetObject(UnmarshallingContext context, ref object key, ref object value, XStreamReader reader)
        {
            string nodeName = reader.GetNodeName();
            object o        = context.ConvertOriginal();

            if (BaseDictionaryConverter <Hashtable> .KEY.Equals(nodeName))
            {
                key = o;
            }
            else
            {
                value = o;
            }
        }
Esempio n. 6
0
        public object FromXml(XStreamReader reader, UnmarshallingContext context)
        {
            int   count  = reader.NoOfChildren();
            Array result = Array.CreateInstance(context.GetTypeFromOtherAssemblies(reader.GetAttribute(ARRAY_TYPE)), count);

            if (count != 0)
            {
                reader.MoveDown();
                for (int i = 0; i < count; i++)
                {
                    result.SetValue(context.ConvertOriginal(), i);
                    reader.MoveNext();
                }
                reader.MoveUp();
            }
            return(result);
        }