public override void SerializeDictionary <K, V>(string name, IDictionary <K, V> dictionary)
 {
     EnterNode(name);
     if (typeof(K) == typeof(string))
     {
         SerializeData serializeData = Archive.GetSerializeData(typeof(V), allowEmptySerializer: true);
         foreach (KeyValuePair <K, V> item in dictionary)
         {
             string name2 = item.Key as string;
             EnterNode(name2);
             WriteObject(null, serializeData, item.Value);
             LeaveNode(name2);
         }
     }
     else
     {
         SerializeData serializeData2 = Archive.GetSerializeData(typeof(K), allowEmptySerializer: true);
         SerializeData serializeData3 = Archive.GetSerializeData(typeof(V), allowEmptySerializer: true);
         foreach (KeyValuePair <K, V> item2 in dictionary)
         {
             EnterNode("e");
             WriteObject("k", serializeData2, item2.Key);
             WriteObject("v", serializeData3, item2.Value);
             LeaveNode("e");
         }
     }
     LeaveNode(name);
 }
示例#2
0
        public virtual void WriteObject(SerializeData staticSerializeData, object value)
        {
            if (!staticSerializeData.UseObjectInfo || !base.UseObjectInfos)
            {
                staticSerializeData.Write(this, value);
                return;
            }
            if (value == null)
            {
                WriteObjectInfo(0, isReference: true, null);
                return;
            }
            if (m_idByObject.TryGetValue(value, out int value2))
            {
                WriteObjectInfo(value2, isReference: true, null);
                return;
            }
            value2 = m_nextObjectId++;
            m_idByObject.Add(value, value2);
            Type type = value.GetType();

            if (type == staticSerializeData.Type)
            {
                WriteObjectInfo(value2, isReference: false, null);
                staticSerializeData.Write(this, value);
            }
            else
            {
                SerializeData serializeData = Archive.GetSerializeData(type, allowEmptySerializer: false);
                WriteObjectInfo(value2, isReference: false, type);
                serializeData.Write(this, value);
            }
        }
        public override void SerializeCollection <T>(string name, string itemName, IEnumerable <T> collection)
        {
            SerializeData serializeData = Archive.GetSerializeData(typeof(T), allowEmptySerializer: true);

            Serialize(null, collection.Count());
            foreach (T item in collection)
            {
                WriteObject(serializeData, item);
            }
        }
        public override void SerializeDictionary <K, V>(string name, IDictionary <K, V> dictionary)
        {
            SerializeData serializeData  = Archive.GetSerializeData(typeof(K), allowEmptySerializer: true);
            SerializeData serializeData2 = Archive.GetSerializeData(typeof(V), allowEmptySerializer: true);

            Serialize(null, dictionary.Count());
            foreach (KeyValuePair <K, V> item in dictionary)
            {
                WriteObject(serializeData, item.Key);
                WriteObject(serializeData2, item.Value);
            }
        }
        public override void SerializeCollection <T>(string name, string itemName, IEnumerable <T> collection)
        {
            EnterNode(name);
            SerializeData serializeData = Archive.GetSerializeData(typeof(T), allowEmptySerializer: true);

            foreach (T item in collection)
            {
                EnterNode(itemName);
                WriteObject(null, serializeData, item);
                LeaveNode(itemName);
            }
            LeaveNode(name);
        }
示例#6
0
        public override void SerializeCollection <T>(string name, ICollection <T> collection)
        {
            SerializeData serializeData = Archive.GetSerializeData(typeof(T), allowEmptySerializer: true);
            int           value         = 0;

            Serialize(null, ref value);
            for (int i = 0; i < value; i++)
            {
                object value2 = null;
                ReadObject(serializeData, ref value2);
                collection.Add((T)value2);
            }
        }
示例#7
0
        public override void SerializeDictionary <K, V>(string name, IDictionary <K, V> dictionary)
        {
            EnterNode(name);
            SerializeData serializeData  = Archive.GetSerializeData(typeof(K), allowEmptySerializer: true);
            SerializeData serializeData2 = Archive.GetSerializeData(typeof(V), allowEmptySerializer: true);

            if (typeof(K) == typeof(string))
            {
                using (IEnumerator <XElement> enumerator = Node.Elements().GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        XElement xElement  = Node = enumerator.Current;
                        object   localName = xElement.Name.LocalName;
                        object   value     = null;
                        if (dictionary.TryGetValue((K)localName, out V value2))
                        {
                            value = value2;
                            ReadObject(null, serializeData2, ref value);
                        }
                        else
                        {
                            ReadObject(null, serializeData2, ref value);
                            dictionary.Add((K)localName, (V)value);
                        }
                        Node = Node.Parent;
                    }
                }
            }
            else
            {
                using (IEnumerator <XElement> enumerator = Node.Elements().GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        XElement xElement2 = Node = enumerator.Current;
                        object   value3    = null;
                        object   value4    = null;
                        ReadObject("k", serializeData, ref value3);
                        if (dictionary.TryGetValue((K)value3, out V value5))
                        {
                            value4 = value5;
                        }
                        ReadObject("v", serializeData2, ref value4);
                        dictionary.Add((K)value3, (V)value4);
                        Node = Node.Parent;
                    }
                }
            }
            LeaveNode(name);
        }
示例#8
0
        public override void SerializeCollection <T>(string name, ICollection <T> collection)
        {
            EnterNode(name);
            SerializeData serializeData = Archive.GetSerializeData(typeof(T), allowEmptySerializer: true);

            using (IEnumerator <XElement> enumerator = Node.Elements().GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    XElement xElement = Node = enumerator.Current;
                    object   value    = null;
                    ReadObject(null, serializeData, ref value);
                    collection.Add((T)value);
                    Node = Node.Parent;
                }
            }
            LeaveNode(name);
        }
示例#9
0
        public void ReadObjectWithObjectInfo(SerializeData staticSerializeData, ref object value)
        {
            ReadObjectInfo(out int objectId, out bool isReference, out Type runtimeType);
            if (objectId == 0)
            {
                if (value != null)
                {
                    throw new InvalidOperationException("Serializing null reference into an existing object.");
                }
                return;
            }
            if (isReference)
            {
                if (value != null)
                {
                    throw new InvalidOperationException("Serializing a reference into an existing object.");
                }
                value = m_objectById[objectId];
                return;
            }
            Type          type = (value != null) ? value.GetType() : null;
            SerializeData serializeData;

            if (!(type != null))
            {
                serializeData = ((!(runtimeType != null)) ? staticSerializeData : Archive.GetSerializeData(runtimeType, allowEmptySerializer: false));
            }
            else
            {
                if (runtimeType != null && runtimeType != type)
                {
                    throw new InvalidOperationException("Serialized object has different type than existing object.");
                }
                serializeData = Archive.GetSerializeData(type, allowEmptySerializer: false);
            }
            if (serializeData.AutoConstructObject && value == null)
            {
                value = Activator.CreateInstance(serializeData.Type, nonPublic: true);
            }
            serializeData.Read(this, ref value);
            m_objectById.Add(objectId, value);
        }
示例#10
0
        public override void SerializeDictionary <K, V>(string name, IDictionary <K, V> dictionary)
        {
            SerializeData serializeData  = Archive.GetSerializeData(typeof(K), allowEmptySerializer: true);
            SerializeData serializeData2 = Archive.GetSerializeData(typeof(V), allowEmptySerializer: true);
            int           value          = 0;

            Serialize(null, ref value);
            for (int i = 0; i < value; i++)
            {
                object value2 = null;
                object value3 = null;
                ReadObject(serializeData, ref value2);
                if (dictionary.TryGetValue((K)value2, out V value4))
                {
                    value3 = value4;
                }
                ReadObject(serializeData2, ref value3);
                dictionary.Add((K)value2, (V)value3);
            }
        }
示例#11
0
 public override void Serialize(string name, Type type, object value)
 {
     WriteObject(name, Archive.GetSerializeData(type, allowEmptySerializer: true), value);
 }
示例#12
0
 public override void Serialize(string name, Type type, ref object value)
 {
     ReadObject(Archive.GetSerializeData(type, allowEmptySerializer: true), ref value);
 }
示例#13
0
        public void ReadObjectWithoutObjectInfo(SerializeData staticSerializeData, ref object value)
        {
            Type          type          = (value != null) ? value.GetType() : null;
            SerializeData serializeData = (!(type == null) && !(staticSerializeData.Type == type)) ? Archive.GetSerializeData(type, allowEmptySerializer: false) : staticSerializeData;

            if (serializeData.AutoConstructObject && value == null)
            {
                value = Activator.CreateInstance(serializeData.Type, nonPublic: true);
            }
            serializeData.Read(this, ref value);
        }