示例#1
0
 protected virtual Serializer <TContext> CreateFlagSerializer(PropertyInfo property,
                                                              XmlFlagAttribute flagAttribute)
 {
     return(CreateFlagSerializer(
                property,
                string.IsNullOrEmpty(flagAttribute.Name) ? property.Name : flagAttribute.Name,
                flagAttribute.Namespace,
                flagAttribute.Prefix));
 }
示例#2
0
        void ProcessType()
        {
            attribute_deserializers = new Dictionary <string, ObjectDeserializer> ();
            element_deserializers   = new Dictionary <string, ObjectDeserializer> ();

            foreach (var property in Properties)
            {
                XmlElementAttribute   element_attribute    = null;
                XmlFlagAttribute      flag_attribute       = null;
                XmlArrayAttribute     array_attribute      = null;
                XmlArrayItemAttribute array_item_attribute = null;
                XmlAttributeAttribute attribute_attribute  = null;

                foreach (var custom_attribute in property.GetCustomAttributes(false))
                {
                    if (custom_attribute is DoNotDeserializeAttribute)
                    {
                        element_attribute   = null;
                        flag_attribute      = null;
                        array_attribute     = null;
                        attribute_attribute = null;
                        value_property      = null;
                        break;
                    }

                    var element = custom_attribute as XmlElementAttribute;
                    if (element != null)
                    {
                        element_attribute = element;
                        continue;
                    }

                    var flag = custom_attribute as XmlFlagAttribute;
                    if (flag != null)
                    {
                        flag_attribute = flag;
                        continue;
                    }

                    var array = custom_attribute as XmlArrayAttribute;
                    if (array != null)
                    {
                        array_attribute = array;
                        continue;
                    }

                    var array_item = custom_attribute as XmlArrayItemAttribute;
                    if (array_item != null)
                    {
                        array_item_attribute = array_item;
                        continue;
                    }

                    var attribute = custom_attribute as XmlAttributeAttribute;
                    if (attribute != null)
                    {
                        attribute_attribute = attribute;
                        continue;
                    }

                    if (custom_attribute is XmlValueAttribute)
                    {
                        // TODO check if this isn't null and throw
                        value_property = property;
                        continue;
                    }
                }

                if (element_attribute != null)
                {
                    var deserializer =
                        CreateCustomDeserializer(property) ??
                        CreateElementDeserializer(property);
                    AddDeserializer(element_deserializers,
                                    CreateName(property.Name, element_attribute.Name, element_attribute.Namespace),
                                    deserializer);
                    continue;
                }

                if (flag_attribute != null)
                {
                    AddDeserializer(element_deserializers,
                                    CreateName(property.Name, flag_attribute.Name, flag_attribute.Namespace),
                                    CreateFlagDeserializer(property));
                    continue;
                }

                if (array_attribute != null)
                {
                    AddDeserializer(element_deserializers,
                                    CreateName(property.Name, array_attribute.Name, array_attribute.Namespace),
                                    CreateArrayElementDeserializer(property));
                    continue;
                }
                else if (array_item_attribute != null)
                {
                    var name       = array_item_attribute.Name;
                    var @namespace = array_item_attribute.Namespace;
                    if (string.IsNullOrEmpty(name))
                    {
                        var item_type      = GetICollection(property.PropertyType).GetGenericArguments()[0];
                        var type_attribute = item_type.GetCustomAttributes(typeof(XmlTypeAttribute), false);
                        if (type_attribute.Length == 0)
                        {
                            name = item_type.Name;
                        }
                        else
                        {
                            var xml_type = (XmlTypeAttribute)type_attribute[0];
                            name       = string.IsNullOrEmpty(xml_type.Name) ? item_type.Name : xml_type.Name;
                            @namespace = xml_type.Namespace;
                        }
                    }
                    AddDeserializer(element_deserializers,
                                    CreateName(name, @namespace),
                                    CreateArrayItemElementDeserializer(property));
                }

                if (attribute_attribute != null)
                {
                    var deserializer =
                        CreateCustomDeserializer(property) ??
                        CreateAttributeDeserializer(property);
                    AddDeserializer(attribute_deserializers,
                                    CreateName(property.Name, attribute_attribute.Name, attribute_attribute.Namespace),
                                    deserializer);
                    continue;
                }
            }
        }
示例#3
0
        protected virtual void ProcessProperty(PropertyInfo property,
                                               ICollection <Serializer <TContext> > attributeSerializers,
                                               ICollection <Serializer <TContext> > elementSerializers)
        {
            XmlAttributeAttribute attribute_attribute  = null;
            XmlElementAttribute   element_attribute    = null;
            XmlFlagAttribute      flag_attribute       = null;
            XmlArrayAttribute     array_attribute      = null;
            XmlArrayItemAttribute array_item_attribute = null;
            XmlValueAttribute     value_attribute      = null;

            foreach (var custom_attribute in property.GetCustomAttributes(false))
            {
                if (custom_attribute is DoNotSerializeAttribute)
                {
                    attribute_attribute = null;
                    element_attribute   = null;
                    flag_attribute      = null;
                    array_attribute     = null;
                    value_attribute     = null;
                    break;
                }

                var attribute = custom_attribute as XmlAttributeAttribute;
                if (attribute != null)
                {
                    attribute_attribute = attribute;
                    continue;
                }

                var element = custom_attribute as XmlElementAttribute;
                if (element != null)
                {
                    element_attribute = element;
                    continue;
                }

                var flag = custom_attribute as XmlFlagAttribute;
                if (flag != null)
                {
                    flag_attribute = flag;
                    continue;
                }

                var array = custom_attribute as XmlArrayAttribute;
                if (array != null)
                {
                    array_attribute = array;
                    continue;
                }

                var array_item = custom_attribute as XmlArrayItemAttribute;
                if (array_item != null)
                {
                    array_item_attribute = array_item;
                    continue;
                }

                var value = custom_attribute as XmlValueAttribute;
                if (value != null)
                {
                    value_attribute = value;
                    continue;
                }
            }

            if (attribute_attribute != null)
            {
                attributeSerializers.Add(
                    CreateSerializer(property, CreateAttributeSerializer(property, attribute_attribute)));
            }
            else if (element_attribute != null)
            {
                elementSerializers.Add(
                    CreateSerializer(property, CreateElementSerializer(property, element_attribute)));
            }
            else if (flag_attribute != null)
            {
                elementSerializers.Add(
                    CreateSerializer(property, CreateFlagSerializer(property, flag_attribute)));
            }
            else if (array_attribute != null)
            {
                elementSerializers.Add(
                    CreateSerializer(property,
                                     CreateArraySerializer(property, array_attribute, array_item_attribute)));
            }
            else if (array_item_attribute != null)
            {
                elementSerializers.Add(
                    CreateSerializer(property, CreateArrayItemSerializer(property, array_item_attribute)));
            }
            else if (value_attribute != null)
            {
                elementSerializers.Add(
                    CreateSerializer(property, CreateValueSerializer(property)));
            }
        }