1 //------------------------------------------------------------------------------
2 // <copyright file="XmlAttributes.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
8 namespace System
.Xml
.Serialization
{
10 using System
.Reflection
;
11 using System
.Collections
;
12 using System
.ComponentModel
;
14 internal enum XmlAttributeFlags
{
25 ChoiceIdentifier
= 0x400,
26 XmlnsDeclarations
= 0x800,
29 /// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes"]/*' />
31 /// <para>[To be supplied.]</para>
33 public class XmlAttributes
{
34 XmlElementAttributes xmlElements
= new XmlElementAttributes();
35 XmlArrayItemAttributes xmlArrayItems
= new XmlArrayItemAttributes();
36 XmlAnyElementAttributes xmlAnyElements
= new XmlAnyElementAttributes();
37 XmlArrayAttribute xmlArray
;
38 XmlAttributeAttribute xmlAttribute
;
39 XmlTextAttribute xmlText
;
40 XmlEnumAttribute xmlEnum
;
43 object xmlDefaultValue
= null;
44 XmlRootAttribute xmlRoot
;
45 XmlTypeAttribute xmlType
;
46 XmlAnyAttributeAttribute xmlAnyAttribute
;
47 XmlChoiceIdentifierAttribute xmlChoiceIdentifier
;
48 static volatile Type ignoreAttributeType
;
51 /// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlAttributes"]/*' />
53 /// <para>[To be supplied.]</para>
55 public XmlAttributes() {
58 internal XmlAttributeFlags XmlFlags
{
60 XmlAttributeFlags flags
= 0;
61 if (xmlElements
.Count
> 0) flags
|= XmlAttributeFlags
.Elements
;
62 if (xmlArrayItems
.Count
> 0) flags
|= XmlAttributeFlags
.ArrayItems
;
63 if (xmlAnyElements
.Count
> 0) flags
|= XmlAttributeFlags
.AnyElements
;
64 if (xmlArray
!= null) flags
|= XmlAttributeFlags
.Array
;
65 if (xmlAttribute
!= null) flags
|= XmlAttributeFlags
.Attribute
;
66 if (xmlText
!= null) flags
|= XmlAttributeFlags
.Text
;
67 if (xmlEnum
!= null) flags
|= XmlAttributeFlags
.Enum
;
68 if (xmlRoot
!= null) flags
|= XmlAttributeFlags
.Root
;
69 if (xmlType
!= null) flags
|= XmlAttributeFlags
.Type
;
70 if (xmlAnyAttribute
!= null) flags
|= XmlAttributeFlags
.AnyAttribute
;
71 if (xmlChoiceIdentifier
!= null) flags
|= XmlAttributeFlags
.ChoiceIdentifier
;
72 if (xmlns
) flags
|= XmlAttributeFlags
.XmlnsDeclarations
;
77 private static Type IgnoreAttribute
{
79 if (ignoreAttributeType
== null) {
80 ignoreAttributeType
= typeof(object).Assembly
.GetType("System.XmlIgnoreMemberAttribute");
81 if (ignoreAttributeType
== null) {
82 ignoreAttributeType
= typeof(XmlIgnoreAttribute
);
85 return ignoreAttributeType
;
89 /// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlAttributes1"]/*' />
91 /// <para>[To be supplied.]</para>
93 public XmlAttributes(ICustomAttributeProvider provider
) {
94 object[] attrs
= provider
.GetCustomAttributes(false);
96 // most generic <any/> matches everithig
97 XmlAnyElementAttribute wildcard
= null;
98 for (int i
= 0; i
< attrs
.Length
; i
++) {
99 if (attrs
[i
] is XmlIgnoreAttribute
|| attrs
[i
] is ObsoleteAttribute
|| attrs
[i
].GetType() == IgnoreAttribute
) {
103 else if (attrs
[i
] is XmlElementAttribute
) {
104 this.xmlElements
.Add((XmlElementAttribute
)attrs
[i
]);
106 else if (attrs
[i
] is XmlArrayItemAttribute
) {
107 this.xmlArrayItems
.Add((XmlArrayItemAttribute
)attrs
[i
]);
109 else if (attrs
[i
] is XmlAnyElementAttribute
) {
110 XmlAnyElementAttribute any
= (XmlAnyElementAttribute
)attrs
[i
];
111 if ((any
.Name
== null || any
.Name
.Length
== 0) && any
.NamespaceSpecified
&& any
.Namespace
== null) {
112 // ignore duplicate wildcards
116 this.xmlAnyElements
.Add((XmlAnyElementAttribute
)attrs
[i
]);
119 else if (attrs
[i
] is DefaultValueAttribute
) {
120 this.xmlDefaultValue
= ((DefaultValueAttribute
)attrs
[i
]).Value
;
122 else if (attrs
[i
] is XmlAttributeAttribute
) {
123 this.xmlAttribute
= (XmlAttributeAttribute
)attrs
[i
];
125 else if (attrs
[i
] is XmlArrayAttribute
) {
126 this.xmlArray
= (XmlArrayAttribute
)attrs
[i
];
128 else if (attrs
[i
] is XmlTextAttribute
) {
129 this.xmlText
= (XmlTextAttribute
)attrs
[i
];
131 else if (attrs
[i
] is XmlEnumAttribute
) {
132 this.xmlEnum
= (XmlEnumAttribute
)attrs
[i
];
134 else if (attrs
[i
] is XmlRootAttribute
) {
135 this.xmlRoot
= (XmlRootAttribute
)attrs
[i
];
137 else if (attrs
[i
] is XmlTypeAttribute
) {
138 this.xmlType
= (XmlTypeAttribute
)attrs
[i
];
140 else if (attrs
[i
] is XmlAnyAttributeAttribute
) {
141 this.xmlAnyAttribute
= (XmlAnyAttributeAttribute
)attrs
[i
];
143 else if (attrs
[i
] is XmlChoiceIdentifierAttribute
) {
144 this.xmlChoiceIdentifier
= (XmlChoiceIdentifierAttribute
)attrs
[i
];
146 else if (attrs
[i
] is XmlNamespaceDeclarationsAttribute
) {
151 this.xmlElements
.Clear();
152 this.xmlArrayItems
.Clear();
153 this.xmlAnyElements
.Clear();
154 this.xmlDefaultValue
= null;
155 this.xmlAttribute
= null;
156 this.xmlArray
= null;
160 this.xmlAnyAttribute
= null;
161 this.xmlChoiceIdentifier
= null;
165 if (wildcard
!= null) {
166 this.xmlAnyElements
.Add(wildcard
);
171 internal static object GetAttr(ICustomAttributeProvider provider
, Type attrType
) {
172 object[] attrs
= provider
.GetCustomAttributes(attrType
, false);
173 if (attrs
.Length
== 0) return null;
177 /// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlElements"]/*' />
179 /// <para>[To be supplied.]</para>
181 public XmlElementAttributes XmlElements
{
182 get { return xmlElements; }
185 /// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlAttribute"]/*' />
187 /// <para>[To be supplied.]</para>
189 public XmlAttributeAttribute XmlAttribute
{
190 get { return xmlAttribute; }
191 set { xmlAttribute = value; }
194 /// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlEnum"]/*' />
196 /// <para>[To be supplied.]</para>
198 public XmlEnumAttribute XmlEnum
{
199 get { return xmlEnum; }
200 set { xmlEnum = value; }
203 /// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlText"]/*' />
205 /// <para>[To be supplied.]</para>
207 public XmlTextAttribute XmlText
{
208 get { return xmlText; }
209 set { xmlText = value; }
212 /// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlArray"]/*' />
214 /// <para>[To be supplied.]</para>
216 public XmlArrayAttribute XmlArray
{
217 get { return xmlArray; }
218 set { xmlArray = value; }
221 /// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlArrayItems"]/*' />
223 /// <para>[To be supplied.]</para>
225 public XmlArrayItemAttributes XmlArrayItems
{
226 get { return xmlArrayItems; }
229 /// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlDefaultValue"]/*' />
231 /// <para>[To be supplied.]</para>
233 public object XmlDefaultValue
{
234 get { return xmlDefaultValue; }
235 set { xmlDefaultValue = value; }
238 /// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlIgnore"]/*' />
240 /// <para>[To be supplied.]</para>
242 public bool XmlIgnore
{
243 get { return xmlIgnore; }
244 set { xmlIgnore = value; }
247 /// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlType"]/*' />
249 /// <para>[To be supplied.]</para>
251 public XmlTypeAttribute XmlType
{
252 get { return xmlType; }
253 set { xmlType = value; }
256 /// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlRoot"]/*' />
258 /// <para>[To be supplied.]</para>
260 public XmlRootAttribute XmlRoot
{
261 get { return xmlRoot; }
262 set { xmlRoot = value; }
265 /// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlAnyElement"]/*' />
267 /// <para>[To be supplied.]</para>
269 public XmlAnyElementAttributes XmlAnyElements
{
270 get { return xmlAnyElements; }
273 /// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlAnyAttribute"]/*' />
275 /// <para>[To be supplied.]</para>
277 public XmlAnyAttributeAttribute XmlAnyAttribute
{
278 get { return xmlAnyAttribute; }
279 set { xmlAnyAttribute = value; }
282 /// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.XmlChoiceIdentifier"]/*' />
283 public XmlChoiceIdentifierAttribute XmlChoiceIdentifier
{
284 get { return xmlChoiceIdentifier; }
287 /// <include file='doc\XmlAttributes.uex' path='docs/doc[@for="XmlAttributes.Xmlns"]/*' />
289 /// <para>[To be supplied.]</para>
292 get { return xmlns; }
293 set { xmlns = value; }