mscorlib(4.0.0.0) API with additions
XmlAttributes.cs
2 using System.Reflection;
3 
5 {
7  [global::__DynamicallyInvokable]
8  public class XmlAttributes
9  {
10  private XmlElementAttributes xmlElements = new XmlElementAttributes();
11 
12  private XmlArrayItemAttributes xmlArrayItems = new XmlArrayItemAttributes();
13 
14  private XmlAnyElementAttributes xmlAnyElements = new XmlAnyElementAttributes();
15 
16  private XmlArrayAttribute xmlArray;
17 
18  private XmlAttributeAttribute xmlAttribute;
19 
20  private XmlTextAttribute xmlText;
21 
22  private XmlEnumAttribute xmlEnum;
23 
24  private bool xmlIgnore;
25 
26  private bool xmlns;
27 
28  private object xmlDefaultValue;
29 
30  private XmlRootAttribute xmlRoot;
31 
32  private XmlTypeAttribute xmlType;
33 
34  private XmlAnyAttributeAttribute xmlAnyAttribute;
35 
36  private XmlChoiceIdentifierAttribute xmlChoiceIdentifier;
37 
38  private static volatile Type ignoreAttributeType;
39 
40  internal XmlAttributeFlags XmlFlags
41  {
42  get
43  {
44  XmlAttributeFlags xmlAttributeFlags = (XmlAttributeFlags)0;
45  if (xmlElements.Count > 0)
46  {
47  xmlAttributeFlags |= XmlAttributeFlags.Elements;
48  }
49  if (xmlArrayItems.Count > 0)
50  {
51  xmlAttributeFlags |= XmlAttributeFlags.ArrayItems;
52  }
53  if (xmlAnyElements.Count > 0)
54  {
55  xmlAttributeFlags |= XmlAttributeFlags.AnyElements;
56  }
57  if (xmlArray != null)
58  {
59  xmlAttributeFlags |= XmlAttributeFlags.Array;
60  }
61  if (xmlAttribute != null)
62  {
63  xmlAttributeFlags |= XmlAttributeFlags.Attribute;
64  }
65  if (xmlText != null)
66  {
67  xmlAttributeFlags |= XmlAttributeFlags.Text;
68  }
69  if (xmlEnum != null)
70  {
71  xmlAttributeFlags |= XmlAttributeFlags.Enum;
72  }
73  if (xmlRoot != null)
74  {
75  xmlAttributeFlags |= XmlAttributeFlags.Root;
76  }
77  if (xmlType != null)
78  {
79  xmlAttributeFlags |= XmlAttributeFlags.Type;
80  }
81  if (xmlAnyAttribute != null)
82  {
83  xmlAttributeFlags |= XmlAttributeFlags.AnyAttribute;
84  }
85  if (xmlChoiceIdentifier != null)
86  {
87  xmlAttributeFlags |= XmlAttributeFlags.ChoiceIdentifier;
88  }
89  if (xmlns)
90  {
91  xmlAttributeFlags |= XmlAttributeFlags.XmlnsDeclarations;
92  }
93  return xmlAttributeFlags;
94  }
95  }
96 
97  private static Type IgnoreAttribute
98  {
99  get
100  {
101  if (ignoreAttributeType == null)
102  {
103  ignoreAttributeType = typeof(object).Assembly.GetType("System.XmlIgnoreMemberAttribute");
104  if (ignoreAttributeType == null)
105  {
106  ignoreAttributeType = typeof(XmlIgnoreAttribute);
107  }
108  }
109  return ignoreAttributeType;
110  }
111  }
112 
115  [global::__DynamicallyInvokable]
117  {
118  [global::__DynamicallyInvokable]
119  get
120  {
121  return xmlElements;
122  }
123  }
124 
127  [global::__DynamicallyInvokable]
129  {
130  [global::__DynamicallyInvokable]
131  get
132  {
133  return xmlAttribute;
134  }
135  [global::__DynamicallyInvokable]
136  set
137  {
138  xmlAttribute = value;
139  }
140  }
141 
144  [global::__DynamicallyInvokable]
146  {
147  [global::__DynamicallyInvokable]
148  get
149  {
150  return xmlEnum;
151  }
152  [global::__DynamicallyInvokable]
153  set
154  {
155  xmlEnum = value;
156  }
157  }
158 
161  [global::__DynamicallyInvokable]
163  {
164  [global::__DynamicallyInvokable]
165  get
166  {
167  return xmlText;
168  }
169  [global::__DynamicallyInvokable]
170  set
171  {
172  xmlText = value;
173  }
174  }
175 
178  [global::__DynamicallyInvokable]
180  {
181  [global::__DynamicallyInvokable]
182  get
183  {
184  return xmlArray;
185  }
186  [global::__DynamicallyInvokable]
187  set
188  {
189  xmlArray = value;
190  }
191  }
192 
195  [global::__DynamicallyInvokable]
197  {
198  [global::__DynamicallyInvokable]
199  get
200  {
201  return xmlArrayItems;
202  }
203  }
204 
207  [global::__DynamicallyInvokable]
208  public object XmlDefaultValue
209  {
210  [global::__DynamicallyInvokable]
211  get
212  {
213  return xmlDefaultValue;
214  }
215  [global::__DynamicallyInvokable]
216  set
217  {
218  xmlDefaultValue = value;
219  }
220  }
221 
225  [global::__DynamicallyInvokable]
226  public bool XmlIgnore
227  {
228  [global::__DynamicallyInvokable]
229  get
230  {
231  return xmlIgnore;
232  }
233  [global::__DynamicallyInvokable]
234  set
235  {
236  xmlIgnore = value;
237  }
238  }
239 
242  [global::__DynamicallyInvokable]
244  {
245  [global::__DynamicallyInvokable]
246  get
247  {
248  return xmlType;
249  }
250  [global::__DynamicallyInvokable]
251  set
252  {
253  xmlType = value;
254  }
255  }
256 
259  [global::__DynamicallyInvokable]
261  {
262  [global::__DynamicallyInvokable]
263  get
264  {
265  return xmlRoot;
266  }
267  [global::__DynamicallyInvokable]
268  set
269  {
270  xmlRoot = value;
271  }
272  }
273 
276  [global::__DynamicallyInvokable]
278  {
279  [global::__DynamicallyInvokable]
280  get
281  {
282  return xmlAnyElements;
283  }
284  }
285 
288  [global::__DynamicallyInvokable]
290  {
291  [global::__DynamicallyInvokable]
292  get
293  {
294  return xmlAnyAttribute;
295  }
296  [global::__DynamicallyInvokable]
297  set
298  {
299  xmlAnyAttribute = value;
300  }
301  }
302 
305  [global::__DynamicallyInvokable]
307  {
308  [global::__DynamicallyInvokable]
309  get
310  {
311  return xmlChoiceIdentifier;
312  }
313  }
314 
318  [global::__DynamicallyInvokable]
319  public bool Xmlns
320  {
321  [global::__DynamicallyInvokable]
322  get
323  {
324  return xmlns;
325  }
326  [global::__DynamicallyInvokable]
327  set
328  {
329  xmlns = value;
330  }
331  }
332 
334  [global::__DynamicallyInvokable]
335  public XmlAttributes()
336  {
337  }
338 
342  {
343  object[] customAttributes = provider.GetCustomAttributes(inherit: false);
344  XmlAnyElementAttribute xmlAnyElementAttribute = null;
345  for (int i = 0; i < customAttributes.Length; i++)
346  {
347  if (customAttributes[i] is XmlIgnoreAttribute || customAttributes[i] is ObsoleteAttribute || customAttributes[i].GetType() == IgnoreAttribute)
348  {
349  xmlIgnore = true;
350  break;
351  }
352  if (customAttributes[i] is XmlElementAttribute)
353  {
354  xmlElements.Add((XmlElementAttribute)customAttributes[i]);
355  }
356  else if (customAttributes[i] is XmlArrayItemAttribute)
357  {
358  xmlArrayItems.Add((XmlArrayItemAttribute)customAttributes[i]);
359  }
360  else if (customAttributes[i] is XmlAnyElementAttribute)
361  {
362  XmlAnyElementAttribute xmlAnyElementAttribute2 = (XmlAnyElementAttribute)customAttributes[i];
363  if ((xmlAnyElementAttribute2.Name == null || xmlAnyElementAttribute2.Name.Length == 0) && xmlAnyElementAttribute2.NamespaceSpecified && xmlAnyElementAttribute2.Namespace == null)
364  {
365  xmlAnyElementAttribute = xmlAnyElementAttribute2;
366  }
367  else
368  {
369  xmlAnyElements.Add((XmlAnyElementAttribute)customAttributes[i]);
370  }
371  }
372  else if (customAttributes[i] is DefaultValueAttribute)
373  {
374  xmlDefaultValue = ((DefaultValueAttribute)customAttributes[i]).Value;
375  }
376  else if (customAttributes[i] is XmlAttributeAttribute)
377  {
378  xmlAttribute = (XmlAttributeAttribute)customAttributes[i];
379  }
380  else if (customAttributes[i] is XmlArrayAttribute)
381  {
382  xmlArray = (XmlArrayAttribute)customAttributes[i];
383  }
384  else if (customAttributes[i] is XmlTextAttribute)
385  {
386  xmlText = (XmlTextAttribute)customAttributes[i];
387  }
388  else if (customAttributes[i] is XmlEnumAttribute)
389  {
390  xmlEnum = (XmlEnumAttribute)customAttributes[i];
391  }
392  else if (customAttributes[i] is XmlRootAttribute)
393  {
394  xmlRoot = (XmlRootAttribute)customAttributes[i];
395  }
396  else if (customAttributes[i] is XmlTypeAttribute)
397  {
398  xmlType = (XmlTypeAttribute)customAttributes[i];
399  }
400  else if (customAttributes[i] is XmlAnyAttributeAttribute)
401  {
402  xmlAnyAttribute = (XmlAnyAttributeAttribute)customAttributes[i];
403  }
404  else if (customAttributes[i] is XmlChoiceIdentifierAttribute)
405  {
406  xmlChoiceIdentifier = (XmlChoiceIdentifierAttribute)customAttributes[i];
407  }
408  else if (customAttributes[i] is XmlNamespaceDeclarationsAttribute)
409  {
410  xmlns = true;
411  }
412  }
413  if (xmlIgnore)
414  {
415  xmlElements.Clear();
416  xmlArrayItems.Clear();
417  xmlAnyElements.Clear();
418  xmlDefaultValue = null;
419  xmlAttribute = null;
420  xmlArray = null;
421  xmlText = null;
422  xmlEnum = null;
423  xmlType = null;
424  xmlAnyAttribute = null;
425  xmlChoiceIdentifier = null;
426  xmlns = false;
427  }
428  else if (xmlAnyElementAttribute != null)
429  {
430  xmlAnyElements.Add(xmlAnyElementAttribute);
431  }
432  }
433 
434  internal static object GetAttr(ICustomAttributeProvider provider, Type attrType)
435  {
436  object[] customAttributes = provider.GetCustomAttributes(attrType, inherit: false);
437  if (customAttributes.Length == 0)
438  {
439  return null;
440  }
441  return customAttributes[0];
442  }
443  }
444 }
Specifies the default value for a property.
XmlAttributes(ICustomAttributeProvider provider)
Initializes a new instance of the T:System.Xml.Serialization.XmlAttributes class and customizes how t...
int Add(XmlAnyElementAttribute attribute)
Adds an T:System.Xml.Serialization.XmlAnyElementAttribute to the collection.
object [] GetCustomAttributes(Type attributeType, bool inherit)
Returns an array of custom attributes defined on this member, identified by type, or an empty array i...
XmlChoiceIdentifierAttribute XmlChoiceIdentifier
Gets or sets an object that allows you to distinguish between a set of choices.
Specifies that the target property, parameter, return value, or class member contains prefixes associ...
Marks the program elements that are no longer in use. This class cannot be inherited.
XmlArrayItemAttributes XmlArrayItems
Gets or sets a collection of objects that specify how the T:System.Xml.Serialization....
Specifies that the member (a field that returns an array of T:System.Xml.XmlElement or T:System....
int Add(XmlArrayItemAttribute attribute)
Adds an T:System.Xml.Serialization.XmlArrayItemAttribute to the collection.
Definition: __Canon.cs:3
XmlElementAttributes XmlElements
Gets a collection of objects that specify how the T:System.Xml.Serialization.XmlSerializer serializes...
Represents an attribute. Valid and default values for the attribute are defined in a document type de...
Definition: XmlAttribute.cs:7
Instructs the M:System.Xml.Serialization.XmlSerializer.Serialize(System.IO.TextWriter,...
bool Xmlns
Gets or sets a value that specifies whether to keep all namespace declarations when an object contain...
XmlAnyElementAttributes XmlAnyElements
Gets the collection of T:System.Xml.Serialization.XmlAnyElementAttribute objects to override.
object XmlDefaultValue
Gets or sets the default value of an XML element or attribute.
Represents a collection of T:System.Xml.Serialization.XmlAnyElementAttribute objects.
Specifies that the T:System.Xml.Serialization.XmlSerializer must serialize the class member as an XML...
Controls XML serialization of the attribute target as an XML root element.
XmlTypeAttribute XmlType
Gets or sets an object that specifies how the T:System.Xml.Serialization.XmlSerializer serializes a c...
Specifies that the member (a field that returns an array of T:System.Xml.XmlAttribute objects) can co...
string Namespace
Gets or sets the XML namespace generated in the XML document.
abstract Assembly Assembly
Gets the T:System.Reflection.Assembly in which the type is declared. For generic types,...
Definition: Type.cs:131
string Name
Gets or sets the XML element name.
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
XmlArrayAttribute XmlArray
Gets or sets an object that specifies how the T:System.Xml.Serialization.XmlSerializer serializes a p...
XmlEnumAttribute XmlEnum
Gets or sets an object that specifies how the T:System.Xml.Serialization.XmlSerializer serializes an ...
Represents the text content of an element or attribute.
Definition: XmlText.cs:6
Represents a collection of attribute objects that control how the T:System.Xml.Serialization....
Definition: XmlAttributes.cs:8
int Add(XmlElementAttribute attribute)
Adds an T:System.Xml.Serialization.XmlElementAttribute to the collection.
int Count
Gets the number of elements contained in the T:System.Collections.CollectionBase instance....
Represents an attribute that specifies the derived types that the T:System.Xml.Serialization....
Controls how the T:System.Xml.Serialization.XmlSerializer serializes an enumeration member.
Specifies that the member can be further detected by using an enumeration.
void Clear()
Removes all objects from the T:System.Collections.CollectionBase instance. This method cannot be over...
Represents a collection of T:System.Xml.Serialization.XmlElementAttribute objects used by the T:Syste...
XmlAnyAttributeAttribute XmlAnyAttribute
Gets or sets the T:System.Xml.Serialization.XmlAnyAttributeAttribute to override.
Controls the XML schema that is generated when the attribute target is serialized by the T:System....
Specifies that the T:System.Xml.Serialization.XmlSerializer must serialize a particular class member ...
Indicates that a public field or property represents an XML element when the T:System....
Indicates to the T:System.Xml.Serialization.XmlSerializer that the member must be treated as XML text...
XmlRootAttribute XmlRoot
Gets or sets an object that specifies how the T:System.Xml.Serialization.XmlSerializer serializes a c...
XmlAttributes()
Initializes a new instance of the T:System.Xml.Serialization.XmlAttributes class.
Provides custom attributes for reflection objects that support them.
Represents a collection of T:System.Xml.Serialization.XmlArrayItemAttribute objects.
bool XmlIgnore
Gets or sets a value that specifies whether or not the T:System.Xml.Serialization....