Пример #1
0
 bool ProcessAttributeAttribute (PropertyInfo propertyInfo, XmlAttributeAttribute attribute)
 {
     if (attribute != null) {
         var name = string.IsNullOrEmpty (attribute.Name) ? propertyInfo.Name : attribute.Name;
         var id = PropertyName.CreateForAttribute (name, attribute.Prefix, null);
         properties[id] = new ValuePropertyVisitor (attribute.OmitIfNull, propertyInfo);
         return true;
     } else {
         return false;
     }
 }
Пример #2
0
        static Serializer CreateSerializerCore(PropertyInfo property, XmlAttributeAttribute attributeAttribute)
        {
            if (!property.CanRead)
            {
                // TODO throw
            }
            var name       = attributeAttribute.Name ?? property.Name;
            var @namespace = attributeAttribute.Namespace;

            return((obj, context) =>
                   context.Writer.WriteAttributeString(name, @namespace, property.GetValue(obj, null).ToString()));
        }
Пример #3
0
 static Serializer CreateSerializer(PropertyInfo property, XmlAttributeAttribute attributeAttribute)
 {
     return(CreateSerializer(CreateSerializerCore(property, attributeAttribute), attributeAttribute.OmitIfNull));
 }
Пример #4
0
        void ProcessMember(PropertyInfo property, List <Serializer> attributeSerializers, List <Serializer> elementSerializers)
        {
            XmlAttributeAttribute attribute_attribute  = null;
            XmlElementAttribute   element_attribute    = null;
            XmlFlagAttribute      flag_attribute       = null;
            XmlArrayAttribute     array_attribute      = null;
            XmlArrayItemAttribute array_item_attribute = null;

            foreach (var custom_attribute in property.GetCustomAttributes(false))
            {
                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;
                }
            }

            if (attribute_attribute != null)
            {
                attributeSerializers.Add(CreateSerializer(property, attribute_attribute));
                return;
            }

            if (element_attribute != null)
            {
                elementSerializers.Add(CreateSerializer(property, element_attribute));
                return;
            }

            if (flag_attribute != null)
            {
                elementSerializers.Add(CreateSerializer(property, flag_attribute));
                return;
            }

            if (array_attribute != null)
            {
                elementSerializers.Add(CreateSerializer(property, array_attribute, array_item_attribute));
                return;
            }
        }