1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
|
//------------------------------------------------------------------------------
// <copyright file="XmlAttributes.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <owner current="true" primary="true">Microsoft</owner>
//------------------------------------------------------------------------------
namespace System.Xml.Serialization {
using System;
using System.Reflection;
using System.Collections;
using System.ComponentModel;
internal enum XmlAttributeFlags {
Enum = 0x1,
Array = 0x2,
Text = 0x4,
ArrayItems = 0x8,
Elements = 0x10,
Attribute = 0x20,
Root = 0x40,
Type = 0x80,
AnyElements = 0x100,
AnyAttribute = 0x200,
ChoiceIdentifier = 0x400,
XmlnsDeclarations = 0x800,
}
/// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public class XmlAttributes {
XmlElementAttributes xmlElements = new XmlElementAttributes();
XmlArrayItemAttributes xmlArrayItems = new XmlArrayItemAttributes();
XmlAnyElementAttributes xmlAnyElements = new XmlAnyElementAttributes();
XmlArrayAttribute xmlArray;
XmlAttributeAttribute xmlAttribute;
XmlTextAttribute xmlText;
XmlEnumAttribute xmlEnum;
bool xmlIgnore;
bool xmlns;
object xmlDefaultValue = null;
XmlRootAttribute xmlRoot;
XmlTypeAttribute xmlType;
XmlAnyAttributeAttribute xmlAnyAttribute;
XmlChoiceIdentifierAttribute xmlChoiceIdentifier;
static volatile Type ignoreAttributeType;
/// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlAttributes"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public XmlAttributes() {
}
internal XmlAttributeFlags XmlFlags {
get {
XmlAttributeFlags flags = 0;
if (xmlElements.Count > 0) flags |= XmlAttributeFlags.Elements;
if (xmlArrayItems.Count > 0) flags |= XmlAttributeFlags.ArrayItems;
if (xmlAnyElements.Count > 0) flags |= XmlAttributeFlags.AnyElements;
if (xmlArray != null) flags |= XmlAttributeFlags.Array;
if (xmlAttribute != null) flags |= XmlAttributeFlags.Attribute;
if (xmlText != null) flags |= XmlAttributeFlags.Text;
if (xmlEnum != null) flags |= XmlAttributeFlags.Enum;
if (xmlRoot != null) flags |= XmlAttributeFlags.Root;
if (xmlType != null) flags |= XmlAttributeFlags.Type;
if (xmlAnyAttribute != null) flags |= XmlAttributeFlags.AnyAttribute;
if (xmlChoiceIdentifier != null) flags |= XmlAttributeFlags.ChoiceIdentifier;
if (xmlns) flags |= XmlAttributeFlags.XmlnsDeclarations;
return flags;
}
}
private static Type IgnoreAttribute {
get {
if (ignoreAttributeType == null) {
ignoreAttributeType = typeof(object).Assembly.GetType("System.XmlIgnoreMemberAttribute");
if (ignoreAttributeType == null) {
ignoreAttributeType = typeof(XmlIgnoreAttribute);
}
}
return ignoreAttributeType;
}
}
/// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlAttributes1"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public XmlAttributes(ICustomAttributeProvider provider) {
object[] attrs = provider.GetCustomAttributes(false);
// 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) {
this.xmlElements.Add((XmlElementAttribute)attrs[i]);
}
else if (attrs[i] is XmlArrayItemAttribute) {
this.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 {
this.xmlAnyElements.Add((XmlAnyElementAttribute)attrs[i]);
}
}
else if (attrs[i] is DefaultValueAttribute) {
this.xmlDefaultValue = ((DefaultValueAttribute)attrs[i]).Value;
}
else if (attrs[i] is XmlAttributeAttribute) {
this.xmlAttribute = (XmlAttributeAttribute)attrs[i];
}
else if (attrs[i] is XmlArrayAttribute) {
this.xmlArray = (XmlArrayAttribute)attrs[i];
}
else if (attrs[i] is XmlTextAttribute) {
this.xmlText = (XmlTextAttribute)attrs[i];
}
else if (attrs[i] is XmlEnumAttribute) {
this.xmlEnum = (XmlEnumAttribute)attrs[i];
}
else if (attrs[i] is XmlRootAttribute) {
this.xmlRoot = (XmlRootAttribute)attrs[i];
}
else if (attrs[i] is XmlTypeAttribute) {
this.xmlType = (XmlTypeAttribute)attrs[i];
}
else if (attrs[i] is XmlAnyAttributeAttribute) {
this.xmlAnyAttribute = (XmlAnyAttributeAttribute)attrs[i];
}
else if (attrs[i] is XmlChoiceIdentifierAttribute) {
this.xmlChoiceIdentifier = (XmlChoiceIdentifierAttribute)attrs[i];
}
else if (attrs[i] is XmlNamespaceDeclarationsAttribute) {
this.xmlns = true;
}
}
if (xmlIgnore) {
this.xmlElements.Clear();
this.xmlArrayItems.Clear();
this.xmlAnyElements.Clear();
this.xmlDefaultValue = null;
this.xmlAttribute = null;
this.xmlArray = null;
this.xmlText = null;
this.xmlEnum = null;
this.xmlType = null;
this.xmlAnyAttribute = null;
this.xmlChoiceIdentifier = null;
this.xmlns = false;
}
else {
if (wildcard != null) {
this.xmlAnyElements.Add(wildcard);
}
}
}
internal static object GetAttr(ICustomAttributeProvider provider, Type attrType) {
object[] attrs = provider.GetCustomAttributes(attrType, false);
if (attrs.Length == 0) return null;
return attrs[0];
}
/// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlElements"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public XmlElementAttributes XmlElements {
get { return xmlElements; }
}
/// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlAttribute"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public XmlAttributeAttribute XmlAttribute {
get { return xmlAttribute; }
set { xmlAttribute = value; }
}
/// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlEnum"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public XmlEnumAttribute XmlEnum {
get { return xmlEnum; }
set { xmlEnum = value; }
}
/// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlText"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public XmlTextAttribute XmlText {
get { return xmlText; }
set { xmlText = value; }
}
/// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlArray"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public XmlArrayAttribute XmlArray {
get { return xmlArray; }
set { xmlArray = value; }
}
/// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlArrayItems"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public XmlArrayItemAttributes XmlArrayItems {
get { return xmlArrayItems; }
}
/// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlDefaultValue"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public object XmlDefaultValue {
get { return xmlDefaultValue; }
set { xmlDefaultValue = value; }
}
/// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlIgnore"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public bool XmlIgnore {
get { return xmlIgnore; }
set { xmlIgnore = value; }
}
/// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlType"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public XmlTypeAttribute XmlType {
get { return xmlType; }
set { xmlType = value; }
}
/// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlRoot"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public XmlRootAttribute XmlRoot {
get { return xmlRoot; }
set { xmlRoot = value; }
}
/// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlAnyElement"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public XmlAnyElementAttributes XmlAnyElements {
get { return xmlAnyElements; }
}
/// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlAnyAttribute"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public XmlAnyAttributeAttribute XmlAnyAttribute {
get { return xmlAnyAttribute; }
set { xmlAnyAttribute = value; }
}
/// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlChoiceIdentifier"]/*' />
public XmlChoiceIdentifierAttribute XmlChoiceIdentifier {
get { return xmlChoiceIdentifier; }
}
/// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.Xmlns"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public bool Xmlns {
get { return xmlns; }
set { xmlns = value; }
}
}
}
|