update readme (#21797)
[mono-project.git] / mcs / class / System.XML / System.Xml.Serialization / XmlTypeMapElementInfo.cs
blobaa0e6d2f7724c3fbbac4658e260b815acca0fd9a
1 //
2 // XmlTypeMapElementInfo.cs:
3 //
4 // Author:
5 // Lluis Sanchez Gual (lluis@ximian.com)
6 //
7 // (C) 2002, 2003 Ximian, Inc. http://www.ximian.com
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;
32 using System.Xml.Schema;
33 using System.Collections;
35 namespace System.Xml.Serialization
37 /// <summary>
38 /// Summary description for XmlTypeMapElementInfo.
39 /// </summary>
40 internal class XmlTypeMapElementInfo
42 string _elementName;
43 string _namespace = "";
44 XmlSchemaForm _form;
45 XmlTypeMapMember _member;
46 object _choiceValue;
47 bool _isNullable;
48 int _nestingLevel; // Only for array items
49 XmlTypeMapping _mappedType;
50 TypeData _type;
51 bool _wrappedElement = true;
52 int _explicitOrder = -1;
54 public XmlTypeMapElementInfo (XmlTypeMapMember member, TypeData type)
56 _member = member;
57 _type = type;
58 if (type.IsValueType && type.IsNullable)
59 _isNullable = true;
62 public TypeData TypeData
64 get { return _type; }
65 set { _type = value; }
68 public object ChoiceValue
70 get { return _choiceValue; }
71 set { _choiceValue = value; }
74 public string ElementName
76 get { return _elementName; }
77 set { _elementName = value; }
80 public string Namespace
82 get { return _namespace; }
83 set { _namespace = value; }
86 public string DataTypeNamespace
88 get
90 if (_mappedType == null) return XmlSchema.Namespace;
91 else return _mappedType.XmlTypeNamespace;
95 public string DataTypeName
97 get
99 if (_mappedType == null) return TypeData.XmlType;
100 else return _mappedType.XmlType;
104 public XmlSchemaForm Form
106 get { return _form; }
107 set { _form = value; }
110 public XmlTypeMapping MappedType
112 get { return _mappedType; }
113 set { _mappedType = value; }
116 public bool IsNullable
118 get { return _isNullable; }
119 set { _isNullable = value; }
122 internal bool IsPrimitive
124 get { return _mappedType == null; }
127 public XmlTypeMapMember Member
129 get { return _member; }
130 set { _member = value; }
133 public int NestingLevel
135 get { return _nestingLevel; }
136 set { _nestingLevel = value; }
139 public bool MultiReferenceType
141 get
143 if (_mappedType != null) return _mappedType.MultiReferenceType;
144 else return false;
148 public bool WrappedElement
150 get { return _wrappedElement; }
151 set { _wrappedElement = value; }
154 public bool IsTextElement
156 get { return ElementName == "<text>"; }
157 set {
158 if (!value)
159 throw new Exception ("INTERNAL ERROR; someone wrote unexpected code in sys.xml");
160 ElementName = "<text>"; Namespace = string.Empty;
164 public bool IsUnnamedAnyElement
166 get { return ElementName == string.Empty; }
167 set {
168 if (!value)
169 throw new Exception ("INTERNAL ERROR; someone wrote unexpected code in sys.xml");
170 ElementName = string.Empty; Namespace = string.Empty;
174 public int ExplicitOrder
176 get { return _explicitOrder; }
177 set { _explicitOrder = value; }
180 public override bool Equals (object other)
182 if (other == null)
183 return false;
184 XmlTypeMapElementInfo oinfo = (XmlTypeMapElementInfo)other;
185 if (_elementName != oinfo._elementName) return false;
186 if (_type.XmlType != oinfo._type.XmlType) return false;
187 if (_namespace != oinfo._namespace) return false;
188 if (_form != oinfo._form) return false;
189 if (_type != oinfo._type) return false;
190 if (_isNullable != oinfo._isNullable) return false;
191 if (_choiceValue != null && !_choiceValue.Equals (oinfo._choiceValue)) return false;
192 if (_choiceValue != oinfo._choiceValue) return false;
193 return true;
196 public override int GetHashCode ()
198 return base.GetHashCode ();
202 class XmlTypeMapElementInfoList: ArrayList
204 public int IndexOfElement (string name, string namspace)
206 for (int n=0; n<Count; n++) {
207 XmlTypeMapElementInfo info = (XmlTypeMapElementInfo) base [n];
208 if (info.ElementName == name && info.Namespace == namspace)
209 return n;
211 return -1;