Example #1
0
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public XmlAttributes(ICustomAttributeProvider provider)
        {
            object[] attrs = provider.GetCustomAttributes(false);

            // most generic <any/> matches everything
            XmlAnyElementAttribute wildcard = null;

            for (int i = 0; i < attrs.Length; i++)
            {
                if (attrs[i] is XmlIgnoreAttribute || attrs[i] is ObsoleteAttribute || attrs[i].GetType() == IgnoreAttribute)
                {
                    _xmlIgnore = true;
                    break;
                }
                else if (attrs[i] is XmlElementAttribute)
                {
                    _xmlElements.Add((XmlElementAttribute)attrs[i]);
                }
                else if (attrs[i] is XmlArrayItemAttribute)
                {
                    _xmlArrayItems.Add((XmlArrayItemAttribute)attrs[i]);
                }
                else if (attrs[i] is XmlAnyElementAttribute)
                {
                    XmlAnyElementAttribute any = (XmlAnyElementAttribute)attrs[i];
                    if ((any.Name == null || any.Name.Length == 0) && any.NamespaceSpecified && any.Namespace == null)
                    {
                        // ignore duplicate wildcards
                        wildcard = any;
                    }
                    else
                    {
                        _xmlAnyElements.Add((XmlAnyElementAttribute)attrs[i]);
                    }
                }
                else if (attrs[i] is DefaultValueAttribute)
                {
                    _xmlDefaultValue = ((DefaultValueAttribute)attrs[i]).Value;
                }
                else if (attrs[i] is XmlAttributeAttribute)
                {
                    _xmlAttribute = (XmlAttributeAttribute)attrs[i];
                }
                else if (attrs[i] is XmlArrayAttribute)
                {
                    _xmlArray = (XmlArrayAttribute)attrs[i];
                }
                else if (attrs[i] is XmlTextAttribute)
                {
                    _xmlText = (XmlTextAttribute)attrs[i];
                }
                else if (attrs[i] is XmlEnumAttribute)
                {
                    _xmlEnum = (XmlEnumAttribute)attrs[i];
                }
                else if (attrs[i] is XmlRootAttribute)
                {
                    _xmlRoot = (XmlRootAttribute)attrs[i];
                }
                else if (attrs[i] is XmlTypeAttribute)
                {
                    _xmlType = (XmlTypeAttribute)attrs[i];
                }
                else if (attrs[i] is XmlAnyAttributeAttribute)
                {
                    _xmlAnyAttribute = (XmlAnyAttributeAttribute)attrs[i];
                }
                else if (attrs[i] is XmlChoiceIdentifierAttribute)
                {
                    _xmlChoiceIdentifier = (XmlChoiceIdentifierAttribute)attrs[i];
                }
                else if (attrs[i] is XmlNamespaceDeclarationsAttribute)
                {
                    _xmlns = true;
                }
            }
            if (_xmlIgnore)
            {
                _xmlElements.Clear();
                _xmlArrayItems.Clear();
                _xmlAnyElements.Clear();
                _xmlDefaultValue     = null;
                _xmlAttribute        = null;
                _xmlArray            = null;
                _xmlText             = null;
                _xmlEnum             = null;
                _xmlType             = null;
                _xmlAnyAttribute     = null;
                _xmlChoiceIdentifier = null;
                _xmlns = false;
            }
            else
            {
                if (wildcard != null)
                {
                    _xmlAnyElements.Add(wildcard);
                }
            }
        }
 public LiteralAttributes(MemberInfo memberInfo)
 {
     foreach (object attr in memberInfo.GetCustomAttributes(false))
     {
         Type type = attr.GetType();
         if (type == s_ignoreType)
         {
             Debug.Assert(false == Ignore, "Too many ignores");
             Ignore = true;
         }
         else if (type == s_choiceType)
         {
             Debug.Assert(XmlChoiceIdentifier == null, "Too many XCIA");
             XmlChoiceIdentifier = (XmlChoiceIdentifierAttribute)attr;
         }
         else if (type == s_elementType)
         {
             if (XmlElements == null)
             {
                 XmlElements = new XmlElementAttributes();
             }
             XmlElements.Add((XmlElementAttribute)attr);
         }
         else if (type == s_attributeType)
         {
             Debug.Assert(XmlAttribute == null, "Too many XAAs");
             XmlAttribute = (XmlAttributeAttribute)attr;
         }
         else if (type == s_arrayType)
         {
             Debug.Assert(XmlArray == null, "Too many XAAs");
             XmlArray = (XmlArrayAttribute)attr;
         }
         else if (type == s_arrayItemType)
         {
             if (XmlArrayItems == null)
             {
                 XmlArrayItems = new XmlArrayItemAttributes();
             }
             XmlArrayItems.Add((XmlArrayItemAttribute)attr);
         }
         else if (type == s_nsDeclType)
         {
             Debug.Assert(XmlNamespaceDeclaration == null, "Too many XNDAs");
             XmlNamespaceDeclaration = (XmlNamespaceDeclarationsAttribute)attr;
             Xmlns = true;
         }
         else if (type == s_textType)
         {
             Debug.Assert(XmlText == null, "Too many XTAs");
             XmlText = (XmlTextAttribute)attr;
         }
         else if (type == s_anyAttrType)
         {
             Debug.Assert(XmlAnyAttribute == null, "Too many XAAAs");
             XmlAnyAttribute = (XmlAnyAttributeAttribute)attr;
         }
         else if (type == s_anyEltType)
         {
             if (XmlAnyElements == null)
             {
                 XmlAnyElements = new XmlAnyElementAttributes();
             }
             XmlAnyElements.Add((XmlAnyElementAttribute)attr);
         }
         else if (type == s_enumType)
         {
             XmlEnum = (XmlEnumAttribute)attr;
         }
         else
         {
             base.processAttribute(attr);
         }
     }
 }