2 // XmlTypeMapMemberElement.cs:
5 // Lluis Sanchez Gual (lluis@ximian.com)
7 // (C) 2002, 2003 Ximian, Inc. http://www.ximian.com
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.
32 using System.Collections;
33 using System.Globalization;
35 namespace System.Xml.Serialization
37 // XmlTypeMapMemberElement
38 // A member of a class that must be serialized as an XmlElement
40 internal class XmlTypeMapMemberElement: XmlTypeMapMember
42 XmlTypeMapElementInfoList _elementInfo;
44 bool _isTextCollector;
46 public XmlTypeMapMemberElement()
50 public XmlTypeMapElementInfoList ElementInfo
54 if (_elementInfo == null) _elementInfo = new XmlTypeMapElementInfoList ();
57 set { _elementInfo = value; }
60 public string ChoiceMember
62 get { return _choiceMember; }
63 set { _choiceMember = value; }
66 public XmlTypeMapElementInfo FindElement (object ob, object memberValue)
68 if (_elementInfo.Count == 1)
69 return (XmlTypeMapElementInfo) _elementInfo[0];
70 else if (_choiceMember != null)
72 object value = GetValue (ob, _choiceMember);
73 string choiceValue = value is IFormattable ? ((IFormattable) value).ToString (null, CultureInfo.InvariantCulture) : value.ToString();
74 foreach (XmlTypeMapElementInfo elem in _elementInfo)
75 if (elem.ChoiceValue == choiceValue) return elem;
79 if (memberValue == null)
80 return (XmlTypeMapElementInfo) _elementInfo[0];
81 Type type = memberValue.GetType();
82 foreach (XmlTypeMapElementInfo elem in _elementInfo)
83 if (elem.TypeData.Type == type) return elem;
88 public bool IsXmlTextCollector
90 get { return _isTextCollector; }
91 set { _isTextCollector = value; }
95 // XmlTypeMapMemberList
96 // A member of a class that must be serialized as a list
98 internal class XmlTypeMapMemberList : XmlTypeMapMemberElement
100 public XmlTypeMapping ListTypeMapping
102 get { return ((XmlTypeMapElementInfo) ElementInfo[0]).MappedType; }
105 public string ElementName
107 get { return ((XmlTypeMapElementInfo) ElementInfo[0]).ElementName; }
110 public string Namespace
112 get { return ((XmlTypeMapElementInfo) ElementInfo[0]).Namespace; }
116 // XmlTypeMapMemberFlatList
117 // A member of a class that must be serialized as a flat list
119 internal class XmlTypeMapMemberExpandable : XmlTypeMapMemberElement
123 public int FlatArrayIndex
125 get { return _flatArrayIndex; }
126 set { _flatArrayIndex = value; }
130 internal class XmlTypeMapMemberFlatList : XmlTypeMapMemberExpandable
134 public ListMap ListMap
136 get { return _listMap; }
137 set { _listMap = value; }
141 internal class XmlTypeMapMemberAnyElement : XmlTypeMapMemberExpandable
143 public bool IsElementDefined (string name, string ns)
145 foreach (XmlTypeMapElementInfo elem in ElementInfo)
147 if (elem.IsUnnamedAnyElement) // Default AnyElementAttribute
150 if (elem.ElementName == name && elem.Namespace == ns)
156 public bool IsDefaultAny
160 foreach (XmlTypeMapElementInfo elem in ElementInfo)
162 if (elem.IsUnnamedAnyElement)
169 public bool CanBeText
173 return (ElementInfo.Count > 0) && ((XmlTypeMapElementInfo)ElementInfo[0]).IsTextElement;
178 internal class XmlTypeMapMemberAnyAttribute: XmlTypeMapMember