[corlib] Fixed StringBuilder construction bugs in marshalling caused by changes to...
[mono.git] / mcs / class / corlib / System.Runtime.Serialization / SerializationInfo.cs
index b36c92dd17014c4a2cec73e05cca6c968ce1c02c..0437329c1f4f9775da82176ff75545aa545d86ee 100644 (file)
 //
 
 using System;
-using System.Collections;
+using System.Collections.Generic;
 
 namespace System.Runtime.Serialization
 {
-#if NET_2_0
        [System.Runtime.InteropServices.ComVisibleAttribute (true)]
-#endif
        public sealed class SerializationInfo
        {
-               Hashtable serialized = new Hashtable ();
-               ArrayList values = new ArrayList ();
+               Dictionary<string, SerializationEntry> serialized = new Dictionary<string, SerializationEntry> ();
+               List<SerializationEntry> values = new List<SerializationEntry> ();
 
                string assemblyName; // the assembly being serialized
                string fullTypeName; // the type being serialized.
+               Type objectType;
+               bool isAssemblyNameSetExplicit;
+               bool isFullTypeNameSetExplicit;
 
                IFormatterConverter converter;
                
@@ -57,6 +58,7 @@ namespace System.Runtime.Serialization
                        assemblyName = type.Assembly.FullName;
                        fullTypeName = type.FullName;
                        converter = new FormatterConverter ();
+                       objectType = type;
                }
                
                /* used by the runtime */
@@ -67,6 +69,7 @@ namespace System.Runtime.Serialization
                        assemblyName = type.Assembly.FullName;
                        fullTypeName = type.FullName;
                        converter = new FormatterConverter ();
+                       objectType = type;
 
                        for (int i = 0; i < len; i++) {
                                serialized.Add (data [i].Name, data [i]);
@@ -87,6 +90,7 @@ namespace System.Runtime.Serialization
                        this.converter = converter;
                        assemblyName = type.Assembly.FullName;
                        fullTypeName = type.FullName;
+                       objectType = type;
                }
 
                // Properties
@@ -98,6 +102,7 @@ namespace System.Runtime.Serialization
                                if (value == null)
                                        throw new ArgumentNullException ("Argument is null.");
                                assemblyName = value;
+                               isAssemblyNameSetExplicit = true;
                        }
                }
                
@@ -109,6 +114,7 @@ namespace System.Runtime.Serialization
                                if ( value == null)
                                        throw new ArgumentNullException ("Argument is null.");
                                fullTypeName = value;
+                               isFullTypeNameSetExplicit = true;
                        }
                }
                
@@ -117,6 +123,24 @@ namespace System.Runtime.Serialization
                        get { return serialized.Count; }
                }
 
+               public bool IsAssemblyNameSetExplicit {
+                       get {
+                               return isAssemblyNameSetExplicit;
+                       }
+               }
+
+               public bool IsFullTypeNameSetExplicit {
+                       get {
+                               return isFullTypeNameSetExplicit;
+                       }
+               }
+
+               public Type ObjectType {
+                       get {
+                               return objectType;
+                       }
+               }
+
                // Methods
                public void AddValue (string name, object value, Type type)
                {
@@ -143,7 +167,7 @@ namespace System.Runtime.Serialization
                        if (!serialized.ContainsKey (name))
                                throw new SerializationException ("No element named " + name + " could be found.");
                                                
-                       SerializationEntry entry = (SerializationEntry) serialized [name];
+                       SerializationEntry entry = serialized [name];
 
                        if (entry.Value != null && !type.IsInstanceOfType (entry.Value))
                                return converter.Convert (entry.Value, type);
@@ -151,6 +175,11 @@ namespace System.Runtime.Serialization
                                return entry.Value;
                }
 
+               internal bool HasKey (string name)
+               {
+                       return serialized.ContainsKey (name);
+               }
+               
                public void SetType (Type type)
                {
                        if (type == null)
@@ -158,6 +187,9 @@ namespace System.Runtime.Serialization
 
                        fullTypeName = type.FullName;
                        assemblyName = type.Assembly.FullName;
+                       objectType = type;
+                       isAssemblyNameSetExplicit = false;
+                       isFullTypeNameSetExplicit = false;
                }
 
                public SerializationInfoEnumerator GetEnumerator ()
@@ -342,6 +374,7 @@ namespace System.Runtime.Serialization
                }
 
                /* used by the runtime */
+#pragma warning disable 169            
                private SerializationEntry [] get_entries ()
                {
                        SerializationEntry [] res = new SerializationEntry [this.MemberCount];
@@ -352,5 +385,6 @@ namespace System.Runtime.Serialization
                        
                        return res;
                }
+#pragma warning restore 169            
        }
 }