Make some S.X.S types compatible with the SL API (for SDK)
authorSebastien Pouliot <sebastien@ximian.com>
Fri, 6 May 2011 12:02:21 +0000 (08:02 -0400)
committerSebastien Pouliot <sebastien@ximian.com>
Fri, 6 May 2011 12:40:41 +0000 (08:40 -0400)
* XmlAnyElementAttributes.cs:
* XmlArrayItemAttributes.cs:
* XmlElementAttributes.cs:
Under Silverlight API this implement IList only (does not
inherit from CollectionBase).

* XmlCustomFormatter.cs:
* XmlSerializationWriterInterpreter.cs:
Use a Convert.ChangeType override that exists in SL API

* XmlReflectionImporter.cs: Provide an alternative for (missing in SL)
Enum.GetNames and select available (in SL) overloads for parsing and
formatting for enums

* XmlSerializationReader.cs: Fix ToEnum API to use IDictionary (in SL)
instead of Hashtable (even if the SL4 docs still states the later)

* XmlSerializationReaderInterpreter.cs:
* XmlTypeMapping.cs:
Use the default (identical to nonPublic being false) when using
Activator.CreateInstance under SL

* XmlSerializationWriter.cs: Internally use a Queue<T> instead a a Queue
(not available in SL). Also Namespaces (ArrayList) is replaced by
XmlNamespaces (IList) in SL API.

* XmlSerializer.cs: Do not use environment variables in MOONLIGHT (like
the rest of MOBILE). Use Encoding.UTF8 instead of ENcoding.Default since
the later does not exist in SL.

* XmlSerializerImplementation.cs: SL version use IDictionary instead of
Hashtable for properties.

* XmlSerializerNamespaces.cs: Internally use a generic Dictionary
* instead
of a ListDictionary (which is not available in SL)

13 files changed:
mcs/class/System.XML/System.Xml.Serialization/XmlAnyElementAttributes.cs
mcs/class/System.XML/System.Xml.Serialization/XmlArrayItemAttributes.cs
mcs/class/System.XML/System.Xml.Serialization/XmlCustomFormatter.cs
mcs/class/System.XML/System.Xml.Serialization/XmlElementAttributes.cs
mcs/class/System.XML/System.Xml.Serialization/XmlReflectionImporter.cs
mcs/class/System.XML/System.Xml.Serialization/XmlSerializationReader.cs
mcs/class/System.XML/System.Xml.Serialization/XmlSerializationReaderInterpreter.cs
mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriter.cs
mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriterInterpreter.cs
mcs/class/System.XML/System.Xml.Serialization/XmlSerializer.cs
mcs/class/System.XML/System.Xml.Serialization/XmlSerializerImplementation.cs
mcs/class/System.XML/System.Xml.Serialization/XmlSerializerNamespaces.cs
mcs/class/System.XML/System.Xml.Serialization/XmlTypeMapping.cs

index b5b9b8a1c2d0a9a672264c9af3261cbdb097916a..06fb64e10d85a4a946e06021f755ae91c29b9f85 100644 (file)
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-using System.Xml;
-using System.Xml.Serialization;
 using System.Collections;
-using System;
+using System.Collections.Generic;
 
 namespace System.Xml.Serialization
 {
        /// <summary>
        /// Summary description for XmlAnyElementAttributes.
        /// </summary>
-       public class XmlAnyElementAttributes : CollectionBase
-       {
+#if MOONLIGHT
+       public class XmlAnyElementAttributes : IList {
+
+               private List<XmlAnyElementAttribute> List = new List<XmlAnyElementAttribute> ();
+
+               int IList.Add (object value)
+               {
+                       return (List as IList).Add (value);
+               }
+
+               void IList.Clear ()
+               {
+                       List.Clear ();
+               }
+
+               bool IList.Contains (object value)
+               {
+                       return (List as IList).Contains (value);
+               }
+
+               int IList.IndexOf (object value)
+               {
+                       return (List as IList).IndexOf (value);
+               }
+
+               void IList.Insert (int index, object value)
+               {
+                       (List as IList).Insert (index, value);
+               }
+
+               bool IList.IsFixedSize {
+                       get { return (List as IList).IsFixedSize; }
+               }
+
+               bool IList.IsReadOnly {
+                       get { return (List as IList).IsReadOnly; }
+               }
+
+               void IList.Remove (object value)
+               {
+                       (List as IList).Remove (value);
+               }
+
+               void IList.RemoveAt (int index)
+               {
+                       List.RemoveAt (index);
+               }
+
+               object IList.this [int index] {
+                       get { return (List as IList) [index]; }
+                       set { (List as IList) [index] = value; }
+               }
+
+               void ICollection.CopyTo (Array array, int index)
+               {
+                       (List as ICollection).CopyTo (array, index);
+               }
+
+               public int Count {
+                       get { return List.Count; }
+               }
+
+               bool ICollection.IsSynchronized {
+                       get { return (List as ICollection).IsSynchronized; }
+               }
+
+               object ICollection.SyncRoot {
+                       get { return (List as ICollection).SyncRoot; }
+               }
+
+               IEnumerator IEnumerable.GetEnumerator ()
+               {
+                       return (List as IEnumerable).GetEnumerator ();
+               }
+#else
+       public class XmlAnyElementAttributes : CollectionBase {
+#endif
                
                public XmlAnyElementAttribute this[int index] 
                {
@@ -55,7 +128,7 @@ namespace System.Xml.Serialization
 
                public int Add(XmlAnyElementAttribute attribute)
                {
-                       return List.Add(attribute);
+                       return (List as IList).Add (attribute);
                }
 
                public bool Contains(XmlAnyElementAttribute attribute)
index 26a422cbbd29fe19d8f7093f8a2d83507f3b3c22..ab9c0aee08d426c150992eafe21006b94c967550 100644 (file)
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-using System.Xml.Serialization;
 using System.Collections;
-using System;
+using System.Collections.Generic;
 
 namespace System.Xml.Serialization
 {
        /// <summary>
        /// Summary description for XmlArrayItemAttributes.
        /// </summary>
-       public class XmlArrayItemAttributes : CollectionBase
-       {
+#if MOONLIGHT
+       public class XmlArrayItemAttributes : IList {
+
+               private List<XmlArrayItemAttribute> List = new List<XmlArrayItemAttribute> ();
+
+               int IList.Add (object value)
+               {
+                       return (List as IList).Add (value);
+               }
+
+               void IList.Clear ()
+               {
+                       List.Clear ();
+               }
+
+               bool IList.Contains (object value)
+               {
+                       return (List as IList).Contains (value);
+               }
+
+               int IList.IndexOf (object value)
+               {
+                       return (List as IList).IndexOf (value);
+               }
+
+               void IList.Insert (int index, object value)
+               {
+                       (List as IList).Insert (index, value);
+               }
+
+               bool IList.IsFixedSize {
+                       get { return (List as IList).IsFixedSize; }
+               }
+
+               bool IList.IsReadOnly {
+                       get { return (List as IList).IsReadOnly; }
+               }
+
+               void IList.Remove (object value)
+               {
+                       (List as IList).Remove (value);
+               }
+
+               void IList.RemoveAt (int index)
+               {
+                       List.RemoveAt (index);
+               }
+
+               object IList.this [int index] {
+                       get { return (List as IList) [index]; }
+                       set { (List as IList) [index] = value; }
+               }
+
+               void ICollection.CopyTo (Array array, int index)
+               {
+                       (List as ICollection).CopyTo (array, index);
+               }
+
+               public int Count {
+                       get { return List.Count; }
+               }
+
+               bool ICollection.IsSynchronized {
+                       get { return (List as ICollection).IsSynchronized; }
+               }
+
+               object ICollection.SyncRoot {
+                       get { return (List as ICollection).SyncRoot; }
+               }
+
+               IEnumerator IEnumerable.GetEnumerator ()
+               {
+                       return (List as IEnumerable).GetEnumerator ();
+               }
+#else
+       public class XmlArrayItemAttributes : CollectionBase {
+#endif
 
                public XmlArrayItemAttribute this [int index] {
                        get {
@@ -51,7 +125,7 @@ namespace System.Xml.Serialization
 
                public int Add (XmlArrayItemAttribute attribute)
                {
-                       return List.Add(attribute);
+                       return (List as IList).Add (attribute);
                }
 
                public bool Contains(XmlArrayItemAttribute attribute)
index 35bd7ef1566f2c3366c9a7b388a076bb03bc9f1f..44158f5dd5d5c329996593847cf6aa537a668047 100644 (file)
@@ -296,7 +296,7 @@ namespace System.Xml.Serialization {
                                case "duration": return value;
                                default: 
                                        if (type.Type != null)
-                                               return Convert.ChangeType (value, type.Type);
+                                               return Convert.ChangeType (value, type.Type, null);
                                        else
                                                return value;
                        }
index c87718794ab1e383952e3a32a083c4bc4948154d..8f5b755e6d0daf2f47e3f0404b3f8156f6aa97a8 100644 (file)
 //
 
 using System.Collections;
-using System;
+using System.Collections.Generic;
 
 namespace System.Xml.Serialization
 {
        /// <summary>
        /// Summary description for XmlElementAttributes.
        /// </summary>
-       public class XmlElementAttributes : CollectionBase
-       {
+#if MOONLIGHT
+       public class XmlElementAttributes : IList {
+
+               private List<XmlElementAttribute> List = new List<XmlElementAttribute> ();
+
+               int IList.Add (object value)
+               {
+                       return (List as IList).Add (value);
+               }
+
+               void IList.Clear ()
+               {
+                       List.Clear ();
+               }
+
+               bool IList.Contains (object value)
+               {
+                       return (List as IList).Contains (value);
+               }
+
+               int IList.IndexOf (object value)
+               {
+                       return (List as IList).IndexOf (value);
+               }
+
+               void IList.Insert (int index, object value)
+               {
+                       (List as IList).Insert (index, value);
+               }
+
+               bool IList.IsFixedSize {
+                       get { return (List as IList).IsFixedSize; }
+               }
+
+               bool IList.IsReadOnly {
+                       get { return (List as IList).IsReadOnly; }
+               }
+
+               void IList.Remove (object value)
+               {
+                       (List as IList).Remove (value);
+               }
+
+               void IList.RemoveAt (int index)
+               {
+                       List.RemoveAt (index);
+               }
+
+               object IList.this [int index] {
+                       get { return (List as IList) [index]; }
+                       set { (List as IList) [index] = value; }
+               }
+
+               void ICollection.CopyTo (Array array, int index)
+               {
+                       (List as ICollection).CopyTo (array, index);
+               }
+
+               public int Count {
+                       get { return List.Count; }
+               }
+
+               bool ICollection.IsSynchronized {
+                       get { return (List as ICollection).IsSynchronized; }
+               }
+
+               object ICollection.SyncRoot {
+                       get { return (List as ICollection).SyncRoot; }
+               }
+
+               IEnumerator IEnumerable.GetEnumerator ()
+               {
+                       return (List as IEnumerable).GetEnumerator ();
+               }
+#else
+       public class XmlElementAttributes : CollectionBase {
+#endif
                public XmlElementAttribute this [int index] {
                        get {
                                return (XmlElementAttribute)List [index];
@@ -49,7 +124,7 @@ namespace System.Xml.Serialization
 
                public int Add (XmlElementAttribute attribute)
                {
-                       return List.Add (attribute);
+                       return (List as IList).Add (attribute);
                }
 
                public bool Contains(XmlElementAttribute attribute)
index ad3223c3bf470fad463c1cc857f2b0ca5c9904e2..82249ad6ac30bc7bd9b35c1ff8bf632ed59e4535 100644 (file)
@@ -618,7 +618,16 @@ namespace System.Xml.Serialization {
                        helper.RegisterClrType (map, type, map.XmlTypeNamespace);
                        return map;
                }
-
+#if MOONLIGHT
+               // Enum.GetNames is not available in SL API
+               public static System.Collections.Generic.IEnumerable<string> GetEnumNames (Type type)
+               {
+                       System.Collections.Generic.List<string> names = new System.Collections.Generic.List<string> ();
+                       foreach (FieldInfo fi in type.GetFields (BindingFlags.Static | BindingFlags.Public))
+                               names.Add (fi.Name);
+                       return names;
+               }
+#endif
                XmlTypeMapping ImportEnumMapping (TypeData typeData, XmlRootAttribute root, string defaultNamespace)
                {
                        Type type = typeData.Type;
@@ -632,10 +641,13 @@ namespace System.Xml.Serialization {
                        map.IsNullable = false;
                        helper.RegisterClrType (map, type, map.XmlTypeNamespace);
 
-                       string [] names = Enum.GetNames (type);
                        ArrayList members = new ArrayList();
-                       foreach (string name in names)
-                       {
+#if MOONLIGHT
+                       foreach (string name in GetEnumNames (type)) {
+#else
+                       string [] names = Enum.GetNames (type);
+                       foreach (string name in names) {
+#endif
                                FieldInfo field = type.GetField (name);
                                string xmlName = null;
                                if (field.IsDefined(typeof(XmlIgnoreAttribute), false))
@@ -1021,7 +1033,7 @@ namespace System.Xml.Serialization {
                                                        + " enumeration value '{1}' for element '{1} from"
                                                        + " namespace '{2}'.", choiceEnumType, elem.ElementName,
                                                        elem.Namespace));
-                                       elem.ChoiceValue = Enum.Parse (choiceEnumType, cname);
+                                       elem.ChoiceValue = Enum.Parse (choiceEnumType, cname, false);
                                }
                                        
                                list.Add (elem);
@@ -1129,11 +1141,15 @@ namespace System.Xml.Serialization {
                        if (defaultValue == DBNull.Value || typeData.SchemaType != SchemaTypes.Enum)
                                return defaultValue;
 
+#if MOONLIGHT
+                       string namedValue = (defaultValue as Enum).ToString ("g");
+                       string decimalValue = (defaultValue as Enum).ToString ("d");
+#else
                        // get string representation of enum value
                        string namedValue = Enum.Format (typeData.Type, defaultValue, "g");
                        // get decimal representation of enum value
                        string decimalValue = Enum.Format (typeData.Type, defaultValue, "d");
-
+#endif
                        // if decimal representation matches string representation, then
                        // the value is not defined in the enum type (as the "g" format
                        // will return the decimal equivalent of the value if the value
index d5797970b044a419e8c30578a56c5da9616805bb..5783677aa670c7621901b81deaed388a11411829 100644 (file)
@@ -900,10 +900,17 @@ namespace System.Xml.Serialization
                        return XmlCustomFormatter.ToDateTime (value);
                }
 
+#if MOONLIGHT
+               protected static long ToEnum (string value, IDictionary h, string typeName)
+               {
+                       return XmlCustomFormatter.ToEnum (value, (Hashtable) h, typeName, true);
+               }
+#else
                protected static long ToEnum (string value, Hashtable h, string typeName)
                {
                        return XmlCustomFormatter.ToEnum (value, h, typeName, true);
                }
+#endif
 
                protected static DateTime ToTime (string value)
                {
index ab6a2785304199533718852f61b6c32e22df6e1e..bc7bf8dc319f44f5cfea8a142105628b922da1c3 100644 (file)
@@ -231,7 +231,7 @@ namespace System.Xml.Serialization
                                        return ReadTypedPrimitive (AnyType);
             }
 
-                       object ob = Activator.CreateInstance (typeMap.TypeData.Type, true);
+                       object ob = CreateInstance (typeMap.TypeData.Type, true);
 
                        Reader.MoveToElement();
                        bool isEmpty = Reader.IsEmptyElement;
@@ -626,7 +626,7 @@ namespace System.Xml.Serialization
                                        return ReadObject (elem.MappedType, elem.IsNullable, true);
 
                                case SchemaTypes.XmlSerializable:
-                                       object ob = Activator.CreateInstance (elem.TypeData.Type, true);
+                                       object ob = CreateInstance (elem.TypeData.Type, true);
                                        return ReadSerializable ((IXmlSerializable)ob);
 
                                default:
@@ -737,7 +737,7 @@ namespace System.Xml.Serialization
                        else    // Must be IEnumerable
                        {
                                if (list == null) {
-                                       if (canCreateInstance) list = Activator.CreateInstance (type, true);
+                                       if (canCreateInstance) list = CreateInstance (type, true);
                                        else throw CreateReadOnlyCollectionException (type.FullName);
                                }
 
@@ -746,6 +746,15 @@ namespace System.Xml.Serialization
                        }
                }
 
+               static object CreateInstance (Type type, bool nonPublic)
+               {
+#if MOONLIGHT
+                       return Activator.CreateInstance (type); // always false
+#else
+                       return Activator.CreateInstance (type, nonPublic);
+#endif
+               }
+
                object CreateInstance (Type type)
                {
                        return Activator.CreateInstance (type, empty_array);
@@ -756,7 +765,7 @@ namespace System.Xml.Serialization
                        if (listType.IsArray)
                                return EnsureArrayIndex (null, 0, listType.GetElementType());
                        else
-                               return Activator.CreateInstance (listType, true);
+                               return CreateInstance (listType, true);
                }
                
                object InitializeList (TypeData listType)
@@ -764,7 +773,7 @@ namespace System.Xml.Serialization
                        if (listType.Type.IsArray)
                                return null;
                        else
-                               return Activator.CreateInstance (listType.Type, true);
+                               return CreateInstance (listType.Type, true);
                }
 
                void FillList (object list, object items)
@@ -824,7 +833,7 @@ namespace System.Xml.Serialization
                        EnumMap map = (EnumMap) typeMap.ObjectMap;
                        string ev = map.GetEnumName (typeMap.TypeFullName, val);
                        if (ev == null) throw CreateUnknownConstantException (val, typeMap.TypeData.Type);
-                       return Enum.Parse (typeMap.TypeData.Type, ev);
+                       return Enum.Parse (typeMap.TypeData.Type, ev, false);
                }
 
                object ReadXmlSerializableElement (XmlTypeMapping typeMap, bool isNullable)
@@ -834,7 +843,7 @@ namespace System.Xml.Serialization
                        {
                                if (Reader.LocalName == typeMap.ElementName && Reader.NamespaceURI == typeMap.Namespace)
                                {
-                                       object ob = Activator.CreateInstance (typeMap.TypeData.Type, true);
+                                       object ob = CreateInstance (typeMap.TypeData.Type, true);
                                        return ReadSerializable ((IXmlSerializable)ob);
                                }
                                else
index e2153d2cef80725ec7bb287a71f789e43116c9fb..890d22022d9c65b8267d1676f96756e8ae277d19 100644 (file)
@@ -31,6 +31,7 @@
 
 using System;
 using System.Collections;
+using System.Collections.Generic;
 using System.Globalization;
 using System.Text;
 using System.Xml;
@@ -54,7 +55,11 @@ namespace System.Xml.Serialization
 
                ArrayList namespaces;
                XmlWriter writer;
+#if MOONLIGHT
+               Queue<object> referencedElements;
+#else
                Queue referencedElements;
+#endif
                Hashtable callbacks;
                Hashtable serializedObjects;
                const string xmlNamespace = "http://www.w3.org/2000/xmlns/";
@@ -87,10 +92,17 @@ namespace System.Xml.Serialization
 
                #region Properties
 
+#if MOONLIGHT
+               protected IList XmlNamespaces {
+                       get { return namespaces; }
+                       set { namespaces = (value as ArrayList); }
+               }
+#else
                protected ArrayList Namespaces {
                        get { return namespaces; }
                        set { namespaces = value; }
                }
+#endif
 
                protected XmlWriter Writer {
                        get { return writer; }
@@ -492,8 +504,11 @@ namespace System.Xml.Serialization
                {
                        if (ns == null)
                                return;
-
+#if MOONLIGHT
+                       IEnumerable<XmlQualifiedName> namespaces = ns.GetNamespaces ();
+#else
                        ICollection namespaces = ns.Namespaces.Values;
+#endif
                        foreach (XmlQualifiedName qn in namespaces) {
                                if (qn.Namespace != String.Empty && Writer.LookupPrefix (qn.Namespace) != qn.Name)
                                        WriteAttribute ("xmlns", qn.Name, xmlNamespace, qn.Namespace);
@@ -745,7 +760,11 @@ namespace System.Xml.Serialization
                {
                        if (referencedElements == null)  
                        {
+#if MOONLIGHT
+                               referencedElements = new Queue<object> ();
+#else
                                referencedElements = new Queue ();
+#endif
                                InitCallbacks ();
                        }
                }
index 49c7796677b6dec5a691e398999a55ac11b32d17..dad96241215334f66212b022868553e07ce5f4f3 100644 (file)
@@ -296,7 +296,7 @@ namespace System.Xml.Serialization
                                {
                                        if (val.Equals (member.DefaultValue)) return false;
                                        Type t = Enum.GetUnderlyingType(val.GetType());
-                                       val = Convert.ChangeType (val, t);
+                                       val = Convert.ChangeType (val, t, null);
                                }
                                if (val != null && val.Equals (member.DefaultValue)) return false;
                        }
index aff3a76085f9dc60d280af1765dcb4db54f6f50d..326fcd8b268574dd32c84241b928e597278f556b 100644 (file)
@@ -120,7 +120,7 @@ namespace System.Xml.Serialization
                        //       debugging pourposes by adding the "nofallback" option.
                        //       For example: MONO_XMLSERIALIZER_THS=0,nofallback
                        
-#if TARGET_JVM || MOBILE
+#if TARGET_JVM || NET_2_1
                        string db = null;
                        string th = null;
                        generationThreshold = -1;
@@ -422,9 +422,15 @@ namespace System.Xml.Serialization
                        }
                }
 
+#if MOONLIGHT
+               static Encoding DefaultEncoding = Encoding.UTF8;
+#else
+               static Encoding DefaultEncoding = Encoding.Default;
+#endif
+
                public void Serialize (Stream stream, object o)
                {
-                       XmlTextWriter xmlWriter = new XmlTextWriter (stream, System.Text.Encoding.Default);
+                       XmlTextWriter xmlWriter = new XmlTextWriter (stream, DefaultEncoding);
                        xmlWriter.Formatting = Formatting.Indented;
                        Serialize (xmlWriter, o, null);
                }
@@ -443,7 +449,7 @@ namespace System.Xml.Serialization
 
                public void Serialize (Stream stream, object o, XmlSerializerNamespaces namespaces)
                {
-                       XmlTextWriter xmlWriter = new XmlTextWriter (stream, System.Text.Encoding.Default);
+                       XmlTextWriter xmlWriter = new XmlTextWriter (stream, DefaultEncoding);
                        xmlWriter.Formatting = Formatting.Indented;
                        Serialize (xmlWriter, o, namespaces);
                }
index 734c7941476dd2d8012bdf6708f2f9ea9599f843..afeed412c78af5c272f9a10cb7640ee39ca45aff 100644 (file)
@@ -44,6 +44,17 @@ namespace System.Xml.Serialization
                public virtual XmlSerializationReader Reader {
                        get { throw new NotSupportedException (); }
                }
+#if MOONLIGHT
+               public virtual IDictionary ReadMethods {
+                       get { throw new NotSupportedException (); }
+               }
+               public virtual IDictionary TypedSerializers {
+                       get { throw new NotSupportedException (); }
+               }
+               public virtual IDictionary WriteMethods {
+                       get { throw new NotSupportedException (); }
+               }
+#else
                public virtual Hashtable ReadMethods {
                        get { throw new NotSupportedException (); }
                }
@@ -53,6 +64,7 @@ namespace System.Xml.Serialization
                public virtual Hashtable WriteMethods {
                        get { throw new NotSupportedException (); }
                }
+#endif
                public virtual XmlSerializationWriter Writer {
                        get { throw new NotSupportedException (); }
                }
index 902d32b025dc6495846e304030aac6a669ea71e4..1124a46a74730eb83db2929f84fc0f6fad51438d 100644 (file)
@@ -28,9 +28,8 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-using System;
-using System.Xml;
 using System.Collections;
+using System.Collections.Generic;
 using System.Collections.Specialized;
 
 namespace System.Xml.Serialization
@@ -40,19 +39,21 @@ namespace System.Xml.Serialization
        /// </summary>
        public class XmlSerializerNamespaces
        {
-               private ListDictionary namespaces;
-                       
+#if MOONLIGHT
+               private Dictionary<string,XmlQualifiedName> namespaces = new Dictionary<string,XmlQualifiedName> ();
+#else
+               private ListDictionary namespaces = new ListDictionary ();
+#endif
                public XmlSerializerNamespaces ()
                {
-                       namespaces = new ListDictionary ();
                }
-       
+
                public XmlSerializerNamespaces(XmlQualifiedName[] namespaces)
                        : this()
                {
                        foreach(XmlQualifiedName qname in namespaces) 
                        {
-                               this.namespaces[qname.Name] = qname;
+                               this.namespaces.Add (qname.Name, qname);
                        }
                }
        
@@ -87,12 +88,18 @@ namespace System.Xml.Serialization
                        }
                        return null;
                }
-
+#if MOONLIGHT
+               internal IEnumerable<XmlQualifiedName> GetNamespaces ()
+               {
+                       return namespaces.Values;
+               }
+#else
                internal ListDictionary Namespaces
                {
                        get {
                                return namespaces;
                        }
                }
+#endif
        }
 }
index fbef2b3d6819b080d9ac79abc471ac481b06f0db..299aca2d16b66bf195f0a3a24cba9b111e762a1b 100644 (file)
@@ -246,14 +246,15 @@ namespace System.Xml.Serialization
                                return;
                        }
 #endif
-                       IXmlSerializable serializable = (IXmlSerializable)Activator.CreateInstance (typeData.Type, true);
 #if NET_2_0 && !MOONLIGHT
+                       IXmlSerializable serializable = (IXmlSerializable)Activator.CreateInstance (typeData.Type, true);
                        try {
                                _schema = serializable.GetSchema();
                        } catch (Exception) {
                                // LAMESPEC: .NET has a bad exception catch and swallows it silently.
                        }
 #else
+                       IXmlSerializable serializable = (IXmlSerializable)Activator.CreateInstance (typeData.Type);
                        _schema = serializable.GetSchema();
 #endif
 #if !MOONLIGHT