5 // John Donagher (john@webmeta.com)
7 // (C) 2002 John Donagher
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System
.Reflection
;
33 using System
.ComponentModel
;
34 using System
.Collections
;
36 namespace System
.Xml
.Serialization
39 /// Summary description for XmlAttributes.
41 public class XmlAttributes
43 private XmlAnyAttributeAttribute xmlAnyAttribute
;
44 private XmlAnyElementAttributes xmlAnyElements
= new XmlAnyElementAttributes();
45 private XmlArrayAttribute xmlArray
;
46 private XmlArrayItemAttributes xmlArrayItems
= new XmlArrayItemAttributes();
47 private XmlAttributeAttribute xmlAttribute
;
48 private XmlChoiceIdentifierAttribute xmlChoiceIdentifier
;
49 private object xmlDefaultValue
= System
.DBNull
.Value
;
50 private XmlElementAttributes xmlElements
= new XmlElementAttributes();
51 private XmlEnumAttribute xmlEnum
;
52 private bool xmlIgnore
;
54 private XmlRootAttribute xmlRoot
;
55 private XmlTextAttribute xmlText
;
56 private XmlTypeAttribute xmlType
;
58 public XmlAttributes ()
62 public XmlAttributes (ICustomAttributeProvider provider
)
64 object[] attributes
= provider
.GetCustomAttributes(false);
65 foreach(object obj
in attributes
)
67 if(obj
is XmlAnyAttributeAttribute
)
68 xmlAnyAttribute
= (XmlAnyAttributeAttribute
) obj
;
69 else if(obj
is XmlAnyElementAttribute
)
70 xmlAnyElements
.Add((XmlAnyElementAttribute
) obj
);
71 else if(obj
is XmlArrayAttribute
)
72 xmlArray
= (XmlArrayAttribute
) obj
;
73 else if(obj
is XmlArrayItemAttribute
)
74 xmlArrayItems
.Add((XmlArrayItemAttribute
) obj
);
75 else if(obj
is XmlAttributeAttribute
)
76 xmlAttribute
= (XmlAttributeAttribute
) obj
;
77 else if(obj
is XmlChoiceIdentifierAttribute
)
78 xmlChoiceIdentifier
= (XmlChoiceIdentifierAttribute
) obj
;
79 else if(obj
is DefaultValueAttribute
)
80 xmlDefaultValue
= ((DefaultValueAttribute
)obj
).Value
;
81 else if(obj
is XmlElementAttribute
)
82 xmlElements
.Add((XmlElementAttribute
) obj
);
83 else if(obj
is XmlEnumAttribute
)
84 xmlEnum
= (XmlEnumAttribute
) obj
;
85 else if(obj
is XmlIgnoreAttribute
)
87 else if(obj
is XmlNamespaceDeclarationsAttribute
)
89 else if(obj
is XmlRootAttribute
)
90 xmlRoot
= (XmlRootAttribute
) obj
;
91 else if(obj
is XmlTextAttribute
)
92 xmlText
= (XmlTextAttribute
) obj
;
93 else if(obj
is XmlTypeAttribute
)
94 xmlType
= (XmlTypeAttribute
) obj
;
98 #region public properties
99 public XmlAnyAttributeAttribute XmlAnyAttribute
103 return xmlAnyAttribute
;
107 xmlAnyAttribute
= value;
110 public XmlAnyElementAttributes XmlAnyElements
114 return xmlAnyElements
;
117 public XmlArrayAttribute XmlArray
128 public XmlArrayItemAttributes XmlArrayItems
132 return xmlArrayItems
;
135 public XmlAttributeAttribute XmlAttribute
143 xmlAttribute
= value;
146 public XmlChoiceIdentifierAttribute XmlChoiceIdentifier
150 return xmlChoiceIdentifier
;
153 public object XmlDefaultValue
157 return xmlDefaultValue
;
161 xmlDefaultValue
= value;
164 public XmlElementAttributes XmlElements
171 public XmlEnumAttribute XmlEnum
182 public bool XmlIgnore
204 public XmlRootAttribute XmlRoot
214 public XmlTextAttribute XmlText
225 public XmlTypeAttribute XmlType
238 internal void AddKeyHash (System
.Text
.StringBuilder sb
)
242 KeyHelper
.AddField (sb
, 1, xmlIgnore
);
243 KeyHelper
.AddField (sb
, 2, xmlns
);
244 KeyHelper
.AddField (sb
, 3, xmlAnyAttribute
!=null);
246 xmlAnyElements
.AddKeyHash (sb
);
247 xmlArrayItems
.AddKeyHash (sb
);
248 xmlElements
.AddKeyHash (sb
);
250 if (xmlArray
!= null)
251 xmlArray
.AddKeyHash (sb
);
253 if (xmlAttribute
!= null)
254 xmlAttribute
.AddKeyHash (sb
);
256 if (xmlDefaultValue
== null) {
259 else if (!(xmlDefaultValue
is System
.DBNull
)) {
260 string v
= XmlCustomFormatter
.ToXmlString (TypeTranslator
.GetTypeData (xmlDefaultValue
.GetType()), xmlDefaultValue
);
265 xmlEnum
.AddKeyHash (sb
);
268 xmlRoot
.AddKeyHash (sb
);
271 xmlText
.AddKeyHash (sb
);
274 xmlType
.AddKeyHash (sb
);
276 if (xmlChoiceIdentifier
!= null)
277 xmlChoiceIdentifier
.AddKeyHash (sb
);