Ejemplo n.º 1
0
        /**
         * @brief core part of automate serialization
         *
         * @param _doc XmlDocument
         *
         * @result
         * */
        private XmlNode Serial(XmlDocument _doc)
        {
            // name of object
            Type       type = GetThisType();
            XmlElement root = _doc.CreateElement(type.ToString());

            FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
            foreach (FieldInfo field in fields)
            {
                // get attributes
                SerialAttribute[] attributes = (SerialAttribute[])(field.GetCustomAttributes(typeof(SerialAttribute), true));
                if (attributes.Length == 0)
                {
                    continue;
                }
                // get other
                string         fieldName   = field.Name;
                Type           fieldType   = field.FieldType;
                ISerializeType iserializer = FindSuitableSerialType(fieldType);
                if (iserializer != null)
                {
                    XmlNode node = iserializer.Serial(field.GetValue(this), attributes[0], _doc, fieldName);
                    if (node != null)
                    {
                        root.AppendChild(node);
                    }
                }
            }
            return(root);
        }
Ejemplo n.º 2
0
        public System.Xml.XmlNode Serial(object _object, SerialAttribute _attribute, System.Xml.XmlDocument _doc, string _nameField)
        {
            if (_object != null)
            {
                IList          list       = (IList)(_object);
                Type           valueType  = _object.GetType().GetGenericArguments()[0];
                ISerializeType valueIType = Serialable.FindSuitableSerialType(valueType);

                XmlElement root = _doc.CreateElement(typeof(IList).ToString());
                root.SetAttribute("name", _nameField);
                root.SetAttribute("typeinfo", _object.GetType().ToString());

                IEnumerator it = list.GetEnumerator();
                while (it.MoveNext())
                {
//                     XmlNode valueNodeHead = _doc.CreateElement("Value");
//                     root.AppendChild(valueNodeHead);
                    XmlNode valueNode = valueIType.Serial(it.Current, _attribute, _doc, "");
                    root.AppendChild(valueNode);
                }
                return(root);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
        public XmlNode Serial(Object _object, SerialAttribute _attribute, XmlDocument _doc, string _nameField)
        {
            if (_object != null)
            {
                // get value <key, value>
                IDictionary    dictionary   = (IDictionary)(_object);
                Type[]         keyValueType = _object.GetType().GetGenericArguments();
                ISerializeType keyIType     = Serialable.FindSuitableSerialType(keyValueType[0]);
                ISerializeType valueIType   = Serialable.FindSuitableSerialType(keyValueType[1]);

                XmlElement root = _doc.CreateElement(typeof(IDictionary).ToString()); // FROM .Name
                root.SetAttribute("name", _nameField);
                root.SetAttribute("typeinfo", _object.GetType().ToString());

                IDictionaryEnumerator it = dictionary.GetEnumerator();
                while (it.MoveNext())
                {
                    XmlNode keyValueNode = _doc.CreateElement("KeyValue");
                    root.AppendChild(keyValueNode);
                    // key
                    XmlNode keyNodeHead = _doc.CreateElement("Key");
                    keyValueNode.AppendChild(keyNodeHead);
                    XmlNode keyNode = keyIType.Serial(it.Key, _attribute, _doc, "");
                    keyNodeHead.AppendChild(keyNode);
                    // value
                    XmlNode valueNodeHead = _doc.CreateElement("Value");
                    keyValueNode.AppendChild(valueNodeHead);
                    XmlNode valueNode = valueIType.Serial(it.Value, _attribute, _doc, "");
                    valueNodeHead.AppendChild(valueNode);
                }
                return(root);
            }
            else
            {
                return(null);
            }
        }