Example #1
0
        public object Clone(Pointer _pointer, SerialAttribute _attribute, object _original, Dictionary <Pointer, string> _delayBindingTable)
        {
            // get list
            IList list = (IList)(_pointer.GetValue());

            if (list == null)
            {
                Type            fieldType       = _original.GetType();
                ConstructorInfo listConstructor = fieldType.GetConstructor(new Type[0]);
                Debug.Assert(listConstructor != null, "Connot find valid constructor for list");
                list = (IList)(listConstructor.Invoke(new object[0]));
            }
            // get value type
            Type           valueType    = list.GetType().GetGenericArguments()[0];
            ISerializeType valueIType   = Serialable.FindSuitableSerialType(valueType);
            IList          originalList = (IList)_original;

            IEnumerator it    = originalList.GetEnumerator();
            int         index = 0;

            while (it.MoveNext())
            {
                object valueObject = valueIType.Clone(new Pointer(list, index), _attribute, it.Current, _delayBindingTable);
                if (valueObject != null)
                {
                    list.Add(valueObject);
                }
                ++index;
            }
            return(list);
        }
Example #2
0
        public object Unserial(Pointer _pointer, SerialAttribute _attribute, System.Xml.XmlNode _fieldNode, Dictionary <Pointer, string> _delayBindingTable)
        {
            // get list
            IList list = (IList)(_pointer.GetValue());

            if (list == null)
            {
                Type            fieldType       = Type.GetType(((XmlElement)_fieldNode).GetAttribute("typeinfo"));
                ConstructorInfo listConstructor = fieldType.GetConstructor(new Type[0]);
                Debug.Assert(listConstructor != null, "Cannot find valid constructor for list");
                list = (IList)(listConstructor.Invoke(new object[0]));
            }
            // get value type
            Type           valueType  = list.GetType().GetGenericArguments()[0];
            ISerializeType valueIType = Serialable.FindSuitableSerialType(valueType);

            int index = 0;

            foreach (XmlNode valueNode in _fieldNode.ChildNodes)
            {
                //XmlNode valueContentNode = valueNode.FirstChild;
                object valueObject = valueIType.Unserial(new Pointer(list, index), _attribute, valueNode, _delayBindingTable);
                if (valueObject != null)
                {
                    list.Add(valueObject);
                }
                ++index;
            }
            return(list);
        }
        public Object Clone(Pointer _pointer, SerialAttribute _attribute, object _original, Dictionary <Pointer, string> _delayBindingTable)
        {
            // get dictionary
            IDictionary dictionary = (IDictionary)(_pointer.GetValue());

            if (dictionary == null)
            {
                Type            fieldType             = _original.GetType();
                ConstructorInfo dictionaryConstructor = fieldType.GetConstructor(new Type[0]);
                Debug.Assert(dictionaryConstructor != null, "Cannot find valid constructor for dictionary");
                dictionary = (IDictionary)(dictionaryConstructor.Invoke(new object[0]));
            }
            // get key value type
            Type[]         keyValueType       = dictionary.GetType().GetGenericArguments();
            ISerializeType keyIType           = Serialable.FindSuitableSerialType(keyValueType[0]);
            ISerializeType valueIType         = Serialable.FindSuitableSerialType(keyValueType[1]);
            IDictionary    orignialDictionary = (IDictionary)_original;

            IDictionaryEnumerator it = orignialDictionary.GetEnumerator();

            while (it.MoveNext())
            {
                object keyObject   = it.Key;
                object valueObject = valueIType.Clone(new Pointer(dictionary, keyObject), _attribute, it.Value, _delayBindingTable);
                if (valueObject != null)
                {
                    dictionary.Add(keyObject, valueObject);
                }
            }
            return(dictionary);
        }
        public object Unserial(Pointer _pointer, SerialAttribute _attribute, XmlNode _fieldNode, Dictionary <Pointer, string> _delayBindingTable)
        {
            // get dictionary
            IDictionary dictionary = (IDictionary)(_pointer.GetValue());

            if (dictionary == null)
            {
                Type            fieldType             = Type.GetType(((XmlElement)_fieldNode).GetAttribute("typeinfo"));
                ConstructorInfo dictionaryConstructor = fieldType.GetConstructor(new Type[0]);
                Debug.Assert(dictionaryConstructor != null, "Cannot find valid constructor for dictionary");
                dictionary = (IDictionary)(dictionaryConstructor.Invoke(new object[0]));
            }
            // get key value type
            Type[]         keyValueType = dictionary.GetType().GetGenericArguments();
            ISerializeType keyIType     = Serialable.FindSuitableSerialType(keyValueType[0]);
            ISerializeType valueIType   = Serialable.FindSuitableSerialType(keyValueType[1]);

            foreach (XmlNode keyValueNode in _fieldNode.ChildNodes)
            {
                // foreach keyValue
                // key
                XmlNode keyNode        = keyValueNode.SelectSingleNode("Key");
                XmlNode keyContentNode = keyNode.FirstChild;
                // do not support delay binding for key
                object keyObject = keyIType.Unserial(null, _attribute, keyContentNode, _delayBindingTable);
                // value
                XmlNode valueNode        = keyValueNode.SelectSingleNode("Value");
                XmlNode valueContentNode = valueNode.FirstChild;
                object  valueObject      = valueIType.Unserial(new Pointer(dictionary, keyObject), _attribute, valueContentNode, _delayBindingTable);
                // insert into dictionary
                if (valueObject != null)
                {
                    dictionary.Add(keyObject, valueObject);
                }
            }
            return(dictionary);
        }
 public Object Clone(Pointer _pointer, SerialAttribute _attribute, object _original, Dictionary <Pointer, string> _delayBindingTable)
 {
     ((IEffectParameter)_pointer.GetValue()).FromString(((IEffectParameter)_original).ToValueString());
     return(null);
 }
 public object Unserial(Pointer _pointer, SerialAttribute _attribute, XmlNode _fieldNode, Dictionary <Pointer, string> _delayBindingTable)
 {
     ((IEffectParameter)_pointer.GetValue()).FromString(((XmlElement)_fieldNode).GetAttribute("value"));
     return(null);
 }