* XmlTypeAttribute.cs: added property AnonymousType for 2.0
[mono.git] / mcs / class / System.XML / System.Xml.Serialization / XmlTypeMapMemberElement.cs
index 50893a6532533916dea0201e8a2be3c2d485acd3..30b0614e97c524b9a1ea683f4e01d2306293e75d 100644 (file)
@@ -42,6 +42,7 @@ namespace System.Xml.Serialization
                XmlTypeMapElementInfoList _elementInfo;
                string _choiceMember;
                bool _isTextCollector;
+               TypeData _choiceTypeData;
 
                public XmlTypeMapMemberElement()
                {
@@ -63,6 +64,12 @@ namespace System.Xml.Serialization
                        set { _choiceMember = value; }
                }
 
+               public TypeData ChoiceTypeData
+               {
+                       get { return _choiceTypeData; }
+                       set { _choiceTypeData = value; }
+               }
+
                public XmlTypeMapElementInfo FindElement (object ob, object memberValue)
                {
                        if (_elementInfo.Count == 1) 
@@ -70,20 +77,23 @@ namespace System.Xml.Serialization
                        else if (_choiceMember != null)
                        {
                                object value = GetValue (ob, _choiceMember);
-                               string choiceValue = value is IFormattable ? ((IFormattable) value).ToString (null, CultureInfo.InvariantCulture) : value.ToString();
                                foreach (XmlTypeMapElementInfo elem in _elementInfo)
-                                       if (elem.ChoiceValue == choiceValue) return elem;
+                                       if (elem.ChoiceValue != null && elem.ChoiceValue.Equals (value)) return elem;
                        }
                        else
                        {
                                if (memberValue == null)
                                        return (XmlTypeMapElementInfo) _elementInfo[0];
-                               Type type = memberValue.GetType();
                                foreach (XmlTypeMapElementInfo elem in _elementInfo)
-                                       if (elem.TypeData.Type == type) return elem;
+                                       if (elem.TypeData.Type.IsInstanceOfType (memberValue)) return elem;
                        }
                        return null;
                }
+               
+               public void SetChoice (object ob, object choice)
+               {
+                       SetValue (ob, _choiceMember, choice);
+               }
 
                public bool IsXmlTextCollector
                {