示例#1
0
        internal XmlMapping(Type type, PropertyInfo info, string[] value, XmlAttributeType attributeType)
        {
            if (value.Length == 0)
            {
                throw new ArgumentException("Array length cannot be null", nameof(value));
            }

            Type           = type;
            Property       = info;
            AttributeValue = value;
            AttributeType  = attributeType;
        }
        private XmlMapping(Type type, PropertyCache cache, string[] value, XmlAttributeType attributeType)
        {
            if (value.Length == 0)
            {
                throw new ArgumentException("Array length cannot be null.", nameof(value));
            }

            Type           = type;
            PropertyCache  = cache;
            AttributeValue = value;
            AttributeType  = attributeType;
        }
示例#3
0
        internal static MemberExpression Serializer_Name(XmlAttributeType type)
        {
            switch (type)
            {
            case XmlAttributeType.Element:
            case XmlAttributeType.Text:
                return(Serializer_ElementName);

            case XmlAttributeType.Attribute:
                return(Serializer_AttributeName);

            default:
                throw new NotImplementedException($"Don't know how to get name for attribute type '{type}'.");
            }
        }
示例#4
0
        private bool FindXmlAttribute <TAttribute>(PropertyInfo property, List <XmlMapping> mappings, Type type, Func <TAttribute, string> name, XmlAttributeType enumType) where TAttribute : Attribute
        {
            var attributes = property.GetCustomAttributes(typeof(TAttribute)) as IEnumerable <TAttribute>;

            if (attributes != null)
            {
                var list = attributes.ToList();

                if (list.Any())
                {
                    mappings.Add(new XmlMapping(type, property, list.Select(name).ToArray(), enumType));
                }
                else
                {
                    return(false);
                }
                return(true);
            }

            return(false);
        }
        private static bool FindXmlAttribute <TAttribute>(PropertyCache propertyCache, List <XmlMapping> mappings, Type type, Func <TAttribute, string> name, XmlAttributeType enumType) where TAttribute : Attribute
        {
            var attributes = propertyCache.GetAttributes <TAttribute>();

            if (attributes.Length > 0)
            {
                var attribs = attributes.Cast <TAttribute>();

                mappings.Add(new XmlMapping(type, propertyCache, attribs.Select(name).ToArray(), enumType));
                return(true);
            }

            return(false);
        }
示例#6
0
 public LadderBuilder(XmlSerializerGenerator generator, XmlAttributeType attributeType)
 {
     this.generator     = generator;
     this.attributeType = attributeType;
 }