Exemplo n.º 1
0
        private void SerializeComplexType(object obj, XmlElement element)
        {
            Type type = obj.GetType();
            IDictionary <string, FieldInfo> typeFieldInfo = CustomXmlSerializerBase.GetTypeFieldInfo(type);

            foreach (KeyValuePair <string, FieldInfo> current in typeFieldInfo)
            {
                XmlElement newChild = this.SerializeCore(current.Key, current.Value.GetValue(obj));
                element.AppendChild(newChild);
            }
        }
Exemplo n.º 2
0
        private void DeserializeComplexType(object obj, Type objType, XmlNode firstChild)
        {
            IDictionary <string, FieldInfo> typeFieldInfo = CustomXmlSerializerBase.GetTypeFieldInfo(objType);

            for (XmlNode xmlNode = firstChild; xmlNode != null; xmlNode = xmlNode.NextSibling)
            {
                string    name      = xmlNode.Name;
                FieldInfo fieldInfo = null;
                if (typeFieldInfo.TryGetValue(name, out fieldInfo))
                {
                    object value = this.DeserializeCore((XmlElement)xmlNode);
                    fieldInfo.SetValue(obj, value);
                }
            }
        }
Exemplo n.º 3
0
        protected static IDictionary <string, FieldInfo> GetTypeFieldInfo(Type objType)
        {
            string fullName = objType.FullName;
            IDictionary <string, FieldInfo> dictionary;

            if (!CustomXmlSerializerBase.fieldInfoCache.TryGetValue(fullName, out dictionary))
            {
                FieldInfo[] fields = objType.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                Dictionary <string, FieldInfo> dictionary2 = new Dictionary <string, FieldInfo>(fields.Length);
                FieldInfo[] array = fields;
                for (int i = 0; i < array.Length; i++)
                {
                    FieldInfo fieldInfo = array[i];
                    if (!fieldInfo.FieldType.IsSubclassOf(typeof(MulticastDelegate)))
                    {
                        object[] customAttributes = fieldInfo.GetCustomAttributes(typeof(XmlIgnoreAttribute), false);
                        if (customAttributes.Length == 0)
                        {
                            dictionary2.Add(fieldInfo.Name, fieldInfo);
                        }
                    }
                }
                Type baseType = objType.BaseType;
                if (baseType != null && baseType != typeof(object))
                {
                    object[] customAttributes2 = baseType.GetCustomAttributes(typeof(XmlIgnoreBaseTypeAttribute), false);
                    if (customAttributes2.Length == 0)
                    {
                        IDictionary <string, FieldInfo> typeFieldInfo = CustomXmlSerializerBase.GetTypeFieldInfo(baseType);
                        foreach (KeyValuePair <string, FieldInfo> current in typeFieldInfo)
                        {
                            string text = current.Key;
                            if (dictionary2.ContainsKey(text))
                            {
                                text = "base." + text;
                            }
                            dictionary2.Add(text, current.Value);
                        }
                    }
                }
                dictionary = dictionary2;
                CustomXmlSerializerBase.fieldInfoCache.Add(fullName, dictionary);
            }
            return(dictionary);
        }