**** Merged from MCS ****
[mono-project.git] / mcs / class / System.XML / System.Xml.Serialization / XmlAttributes.cs
blobeddc9b0c3bdb72e9c1551b7deb6102ed0bf93a1a
1 //
2 // XmlAttributes.cs:
3 //
4 // Author:
5 // John Donagher (john@webmeta.com)
6 //
7 // (C) 2002 John Donagher
8 //
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:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
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;
32 using System;
33 using System.ComponentModel;
34 using System.Collections;
36 namespace System.Xml.Serialization
38 /// <summary>
39 /// Summary description for XmlAttributes.
40 /// </summary>
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;
53 private bool xmlns;
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)
86 xmlIgnore = true;
87 else if(obj is XmlNamespaceDeclarationsAttribute)
88 xmlns = true;
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
101 get
103 return xmlAnyAttribute;
105 set
107 xmlAnyAttribute = value;
110 public XmlAnyElementAttributes XmlAnyElements
112 get
114 return xmlAnyElements;
117 public XmlArrayAttribute XmlArray
119 get
121 return xmlArray;
123 set
125 xmlArray = value;
128 public XmlArrayItemAttributes XmlArrayItems
130 get
132 return xmlArrayItems;
135 public XmlAttributeAttribute XmlAttribute
137 get
139 return xmlAttribute;
141 set
143 xmlAttribute = value;
146 public XmlChoiceIdentifierAttribute XmlChoiceIdentifier
148 get
150 return xmlChoiceIdentifier;
153 public object XmlDefaultValue
155 get
157 return xmlDefaultValue;
159 set
161 xmlDefaultValue = value;
164 public XmlElementAttributes XmlElements
166 get
168 return xmlElements;
171 public XmlEnumAttribute XmlEnum
173 get
175 return xmlEnum;
177 set
179 xmlEnum = value;
182 public bool XmlIgnore
184 get
186 return xmlIgnore;
188 set
190 xmlIgnore = value;
193 public bool Xmlns
195 get
197 return xmlns;
199 set
201 xmlns = value;
204 public XmlRootAttribute XmlRoot
206 get
208 return xmlRoot;}
209 set
211 xmlRoot = value;
214 public XmlTextAttribute XmlText
216 get
218 return xmlText;
220 set
222 xmlText = value;
225 public XmlTypeAttribute XmlType
227 get
229 return xmlType;
231 set
233 xmlType = value;
236 #endregion
238 internal void AddKeyHash (System.Text.StringBuilder sb)
240 sb.Append ("XA ");
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) {
257 sb.Append ("n");
259 else if (!(xmlDefaultValue is System.DBNull)) {
260 string v = XmlCustomFormatter.ToXmlString (TypeTranslator.GetTypeData (xmlDefaultValue.GetType()), xmlDefaultValue);
261 sb.Append ("v" + v);
264 if (xmlEnum != null)
265 xmlEnum.AddKeyHash (sb);
267 if (xmlRoot != null)
268 xmlRoot.AddKeyHash (sb);
270 if (xmlText != null)
271 xmlText.AddKeyHash (sb);
273 if (xmlType != null)
274 xmlType.AddKeyHash (sb);
276 if (xmlChoiceIdentifier != null)
277 xmlChoiceIdentifier.AddKeyHash (sb);
279 sb.Append ("|");