// 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]
{
public int Add(XmlAnyElementAttribute attribute)
{
- return List.Add(attribute);
+ return (List as IList).Add (attribute);
}
public bool Contains(XmlAnyElementAttribute attribute)
// 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 {
public int Add (XmlArrayItemAttribute attribute)
{
- return List.Add(attribute);
+ return (List as IList).Add (attribute);
}
public bool Contains(XmlArrayItemAttribute attribute)
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;
}
//
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];
public int Add (XmlElementAttribute attribute)
{
- return List.Add (attribute);
+ return (List as IList).Add (attribute);
}
public bool Contains(XmlElementAttribute attribute)
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;
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))
+ " 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);
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
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)
{
return ReadTypedPrimitive (AnyType);
}
- object ob = Activator.CreateInstance (typeMap.TypeData.Type, true);
+ object ob = CreateInstance (typeMap.TypeData.Type, true);
Reader.MoveToElement();
bool isEmpty = Reader.IsEmptyElement;
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:
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);
}
}
}
+ 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);
if (listType.IsArray)
return EnsureArrayIndex (null, 0, listType.GetElementType());
else
- return Activator.CreateInstance (listType, true);
+ return CreateInstance (listType, true);
}
object InitializeList (TypeData listType)
if (listType.Type.IsArray)
return null;
else
- return Activator.CreateInstance (listType.Type, true);
+ return CreateInstance (listType.Type, true);
}
void FillList (object list, object items)
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)
{
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
using System;
using System.Collections;
+using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Xml;
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/";
#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; }
{
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);
{
if (referencedElements == null)
{
+#if MOONLIGHT
+ referencedElements = new Queue<object> ();
+#else
referencedElements = new Queue ();
+#endif
InitCallbacks ();
}
}
{
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;
}
// 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;
}
}
+#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);
}
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);
}
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 (); }
}
public virtual Hashtable WriteMethods {
get { throw new NotSupportedException (); }
}
+#endif
public virtual XmlSerializationWriter Writer {
get { throw new NotSupportedException (); }
}
// 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
/// </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);
}
}
}
return null;
}
-
+#if MOONLIGHT
+ internal IEnumerable<XmlQualifiedName> GetNamespaces ()
+ {
+ return namespaces.Values;
+ }
+#else
internal ListDictionary Namespaces
{
get {
return namespaces;
}
}
+#endif
}
}
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