public XmlAttributes(ICustomAttributeProvider provider) { object[] attributes = provider.GetCustomAttributes(false); foreach (object obj in attributes) { if (obj is XmlAnyAttributeAttribute) { xmlAnyAttribute = (XmlAnyAttributeAttribute)obj; } else if (obj is XmlAnyElementAttribute) { xmlAnyElements.Add((XmlAnyElementAttribute)obj); } else if (obj is XmlArrayAttribute) { xmlArray = (XmlArrayAttribute)obj; } else if (obj is XmlArrayItemAttribute) { xmlArrayItems.Add((XmlArrayItemAttribute)obj); } else if (obj is XmlAttributeAttribute) { xmlAttribute = (XmlAttributeAttribute)obj; } else if (obj is XmlChoiceIdentifierAttribute) { xmlChoiceIdentifier = (XmlChoiceIdentifierAttribute)obj; } else if (obj is DefaultValueAttribute) { xmlDefaultValue = ((DefaultValueAttribute)obj).Value; } else if (obj is XmlElementAttribute) { xmlElements.Add((XmlElementAttribute )obj); } else if (obj is XmlEnumAttribute) { xmlEnum = (XmlEnumAttribute)obj; } else if (obj is XmlIgnoreAttribute) { xmlIgnore = true; } else if (obj is XmlNamespaceDeclarationsAttribute) { xmlns = true; } else if (obj is XmlRootAttribute) { xmlRoot = (XmlRootAttribute)obj; } else if (obj is XmlTextAttribute) { xmlText = (XmlTextAttribute)obj; } else if (obj is XmlTypeAttribute) { xmlType = (XmlTypeAttribute)obj; } } if (xmlIgnore) { xmlAnyAttribute = null; xmlAnyElements.Clear(); xmlArray = null; xmlArrayItems.Clear(); xmlAttribute = null; xmlChoiceIdentifier = null; xmlDefaultValue = null; xmlElements.Clear(); xmlEnum = null; xmlns = false; xmlRoot = null; xmlText = null; xmlType = null; } }
/// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlAttributes1"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public XmlAttributes(MemberInfo memberInfo) { object[] attrs = memberInfo.GetCustomAttributes(false).ToArray(); // most generic <any/> matches everithig 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); } } }
/// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public XmlAttributes(ICustomAttributeProvider provider) { ArgumentNullException.ThrowIfNull(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) { _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 any) { if ((any.Name == null || any.Name.Length == 0) && any.GetNamespaceSpecified() && 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); } } }