static object ReadGeneric <TKey, TValue>(XXmlSerializerInternal serializer, XmlReader reader)
        {
            Dictionary <TKey, TValue> obj = new Dictionary <TKey, TValue>();
            bool is_null;

            while (serializer.ReadTypeStart(reader, out is_null))
            {
                Debug.Assert(is_null == false);
                // Key
                TKey key;
                serializer.ReadTypeStart(reader, out is_null);
                Debug.Assert(is_null == false);// Key 不能为null
                key = (TKey)serializer.InternalRead(reader, typeof(TKey));
                serializer.ReadTypeEnd(reader);
                // Value
                TValue value = default(TValue);
                serializer.ReadTypeStart(reader, out is_null);
                if (is_null == false)
                {
                    value = (TValue)serializer.InternalRead(reader, typeof(TValue));
                }
                obj.Add(key, value);
                serializer.ReadTypeEnd(reader);
            }
            return(obj);
        }
Exemplo n.º 2
0
        public override object Read(XXmlSerializerInternal serializer, XmlReader reader, Type type)
        {
            var    obj = Activator.CreateInstance(type, true);
            bool   is_null;
            string field_name;

            while (ReadFieldStart(reader, out field_name, out is_null))
            {
                var field = type.GetField(field_name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
                if (field == null)
                {
                    // throw ...
                }
                else
                {
                    if (is_null)
                    {
                        field.SetValue(obj, null);
                    }
                    else
                    {
                        field.SetValue(obj, serializer.InternalRead(reader, field.FieldType));
                    }
                }
                serializer.ReadTypeEnd(reader);
            }
            return(obj);
        }
Exemplo n.º 3
0
        static object ReadGeneric <T>(XXmlSerializerInternal serializer, XmlReader reader)
        {
            List <T> obj = new List <T>();
            bool     is_null;

            while (serializer.ReadTypeStart(reader, out is_null))
            {
                T item = default(T);
                if (is_null == false)
                {
                    item = (T)serializer.InternalRead(reader, typeof(T));
                }
                obj.Add(item);
                serializer.ReadTypeEnd(reader);
            }
            return(obj.ToArray());
        }