示例#1
0
        public void SerializeDictionaryObjectFloatEmbedded <KeyType>(string ListName, string KeyName, string ValueName, ref Dictionary <KeyType, float> DictionaryToSerialize)
            where KeyType : XMLSerializable, new()
        {
            if (bReading)
            {
                bool isEmptyElement = InternalReader.IsEmptyElement;
                InternalReader.ReadStartElement(ListName);

                if (!isEmptyElement)
                {
                    int CurrentDepth = InternalReader.Depth;
                    while (InternalReader.Depth >= CurrentDepth)
                    {
                        KeyType NewKey   = new KeyType();
                        float   NewValue = 0.0f;
                        XMLSerializable.SerializeFromXMLEmbedded <KeyType>(ref InternalReader, ref InternalWriter, ref NewKey);
                        NewKey = (KeyType)NewKey.ResolveIDPatching();
                        SerializeFloat(ValueName, ref NewValue);
                        if (NewKey == null)
                        {
                            NewKey = new KeyType();
                        }
                        DictionaryToSerialize.Add(NewKey, NewValue);
                    }
                    InternalReader.ReadEndElement();
                }
            }
            else
            {
                InternalWriter.WriteStartElement(ListName);
                if (DictionaryToSerialize.Count > 0)
                {
                    foreach (KeyValuePair <KeyType, float> CurrentElement in DictionaryToSerialize)
                    {
                        KeyType RefCurrentKey = CurrentElement.Key;
                        XMLSerializable.SerializeFromXMLEmbedded <KeyType>(ref InternalReader, ref InternalWriter, ref RefCurrentKey);
                        float RefCurrentValue = CurrentElement.Value;
                        SerializeFloat(ValueName, ref RefCurrentValue);
                    }
                }
                InternalWriter.WriteEndElement();
            }
        }
示例#2
0
        public void SerializeListEmbedded <ListType>(string ListName, string ElementName, ref List <ListType> ListToSerialize) where ListType : XMLSerializable, new()
        {
            if (bReading)
            {
                bool isEmptyElement = InternalReader.IsEmptyElement;
                InternalReader.ReadStartElement(ListName);

                if (!isEmptyElement)
                {
                    int CurrentDepth = InternalReader.Depth;
                    while (InternalReader.Depth >= CurrentDepth)
                    {
                        //					InternalReader.ReadStartElement(ElementName);
                        ListType NewElement = new ListType();
                        XMLSerializable.SerializeFromXMLEmbedded <ListType>(ref InternalReader, ref InternalWriter, ref NewElement);
                        NewElement = (ListType)NewElement.ResolveIDPatching();
                        ListToSerialize.Add(NewElement);
                        //					InternalReader.ReadEndElement();
                    }
                    InternalReader.ReadEndElement();
                }
            }
            else
            {
                InternalWriter.WriteStartElement(ListName);
                if (ListToSerialize.Count > 0)
                {
                    foreach (ListType CurrentElement in ListToSerialize)
                    {
                        ListType RefCurrentElement = CurrentElement;
                        XMLSerializable.SerializeFromXMLEmbedded <ListType>(ref InternalReader, ref InternalWriter, ref RefCurrentElement);
                    }
                }
                InternalWriter.WriteEndElement();
            }
        }
示例#3
0
        public void SerializeDictionaryStringEmbedded <ValueType>(string ListName, string KeyName, string ValueName, ref Dictionary <string, ValueType> DictionaryToSerialize)
            where ValueType : XMLSerializable, new()
        {
            if (bReading)
            {
                bool isEmptyElement = InternalReader.IsEmptyElement;
                InternalReader.ReadStartElement(ListName);

                if (!isEmptyElement)
                {
                    int CurrentDepth = InternalReader.Depth;
                    while (InternalReader.Depth >= CurrentDepth)
                    {
                        string NewKey = "";

                        SerializeString(KeyName, ref NewKey);

                        ValueType NewValue = new ValueType();

                        if (InternalReader.IsStartElement())
                        {
                            string NextElementType = InternalReader.Name;

                            object Temp = TypeUtils.GetNewObjectOfTypeString(NextElementType);

                            if (typeof(ValueType).IsAssignableFrom(Temp.GetType()))
                            {
                                NewValue = (ValueType)Temp;
                            }

                            bReadStartElement = true;
                        }

                        XMLSerializable.SerializeFromXMLEmbedded <ValueType>(ref InternalReader, ref InternalWriter, ref NewValue);
                        NewValue = (ValueType)NewValue.ResolveIDPatching();

                        if (NewKey == null)
                        {
                            NewKey = "";
                        }

                        if (NewValue == null)
                        {
                            NewValue = new ValueType();
                        }

                        DictionaryToSerialize.Add(NewKey, NewValue);
                    }
                    InternalReader.ReadEndElement();
                }
            }
            else
            {
                InternalWriter.WriteStartElement(ListName);
                if (DictionaryToSerialize.Count > 0)
                {
                    foreach (KeyValuePair <string, ValueType> CurrentElement in DictionaryToSerialize)
                    {
                        string RefCurrentKey = CurrentElement.Key;
                        SerializeString(KeyName, ref RefCurrentKey);
                        ValueType RefCurrentValue = CurrentElement.Value;
                        XMLSerializable.SerializeFromXMLEmbedded <ValueType>(ref InternalReader, ref InternalWriter, ref RefCurrentValue);
                    }
                }
                InternalWriter.WriteEndElement();
            }
        }