2
0
Эх сурвалжийг харах

Serialization bits for System.Collection.Hashtable, System.Reflection.AssemblyName and System.Security.SecurityException

svn path=/trunk/mcs/; revision=2259
Duncan Mak 24 жил өмнө
parent
commit
01beb5e5b9

+ 5 - 0
mcs/class/corlib/System.Collections/ChangeLog

@@ -1,3 +1,8 @@
+2002-02-07  Duncan Mak  <[email protected]>
+
+	* Hashtable.cs: Implemented parts of the ISerializable
+	interface. GetObjectData () is good, but serialization constructor
+	needs some more love.
 
 Sat Jan 5 15:56:54 CET 2002 Paolo Molaro <[email protected]>
 

+ 24 - 5
mcs/class/corlib/System.Collections/Hashtable.cs

@@ -9,6 +9,7 @@
 
 using System;
 using System.Collections;
+using System.Runtime.Serialization;
 
 
 // TODO: 1. Interfaces to implement: ISerializable and IDeserializationCallback;
@@ -21,7 +22,7 @@ namespace System.Collections {
 
 	[MonoTODO]
 	public class Hashtable : IDictionary, ICollection, 
-	                         IEnumerable, ICloneable
+		IEnumerable, ICloneable, ISerializable
 	{
 
 		internal struct Slot {
@@ -191,6 +192,17 @@ namespace System.Collections {
 		{
 		}
 
+		[MonoTODO]
+		protected Hashtable (SerializationInfo info, StreamingContext context)
+		{
+//			loadFactor = info.GetValue ("LoadFactor", Type.GetType ("System.Float"));
+//			comparerRef = info.GetValue ("Comparer", typeof (object));
+//			hcpRef = info.GetValue ("HashCodeProvider", typeof (object));
+//			this.Count = info.GetValue ("HashSize");
+// 			this.Keys = info.GetValue ("Keys");
+// 			this.Values = info.GetValue ("Values");
+ 		}
+
 		//
 		// Properties
 		//
@@ -391,10 +403,17 @@ namespace System.Collections {
 			return ht;
 		}
 
-
-
-		//[MonoTODO]
-		//public virtual void GetObjectData (SerializationInfo info, StreamingContext context) {}
+		[MonoTODO]
+		public virtual void GetObjectData (SerializationInfo info, StreamingContext context)
+		{
+			info.AddValue ("LoadFactor", loadFactor);
+			info.AddValue ("Version", 0); // TODO?
+			info.AddValue ("Comparer", comparerRef);
+			info.AddValue ("HashCodeProvider", hcpRef);
+			info.AddValue ("HashSize", this.Count );
+			info.AddValue ("Keys", this.Keys);
+			info.AddValue ("Values", this.Values);
+		}
 
 		//[MonoTODO]
 		//public virtual void OnDeserialization (object sender);

+ 12 - 2
mcs/class/corlib/System.Reflection/AssemblyName.cs

@@ -1,3 +1,4 @@
+
 //
 // System.Reflection/AssemblyName.cs
 //
@@ -13,7 +14,8 @@ using System.Runtime.Serialization;
 
 namespace System.Reflection {
 
-	public class AssemblyName /* : ICloneable, ISerializable, IDeserializationCallback */ {
+	public class AssemblyName  : ISerializable // ICloneable, , IDeserializationCallback
+	{
 		string name;
 		string codebase;
 		Version version;
@@ -25,6 +27,9 @@ namespace System.Reflection {
 
 		public AssemblyName (SerializationInfo si, StreamingContext sc)
 		{
+			name = si.GetString ("_Name");
+			codebase = si.GetString ("_CodeBase");
+			version = (Version)si.GetValue ("_Version", typeof (Version));
 		}
 
 		public virtual string Name {
@@ -74,6 +79,11 @@ namespace System.Reflection {
 			return false;
 		}
 
+		public void GetObjectData (SerializationInfo info, StreamingContext context)
+		{
+			info.AddValue ("_Name", name);
+			info.AddValue ("_CodeBase", codebase);
+			info.AddValue ("_Version", version);
+		}
 	}
-
 }

+ 5 - 0
mcs/class/corlib/System.Reflection/ChangeLog

@@ -1,3 +1,8 @@
+2002-02-07  Duncan Mak  <[email protected]>
+
+	* AssemblyName.cs: Implemented ISerializable interface for the
+	fields that we have.
+
 2002-02-05  Duncan Mak  <[email protected]>
 	
 	* Missing.cs: 

+ 5 - 0
mcs/class/corlib/System.Security/ChangeLog

@@ -1,3 +1,8 @@
+2002-02-07  Duncan Mak  <[email protected]>
+
+	* SecurityException.cs: Reformatted to fit the form of other
+	Exceptions. Added serialization bits.
+
 2002-01-05  Ravi Pratap  <[email protected]>
 
 	* SecurityElement.cs : Insert MonoTODO attribute.

+ 48 - 13
mcs/class/corlib/System.Security/SecurityException.cs

@@ -12,32 +12,67 @@ using System.Globalization;
 
 namespace System.Security {
 	public class SecurityException : Exception {
-	
+
+		// Fields
 		string permissionState;
 		Type permissionType;
 
-		public string PermissionState {get { return permissionState; } }
-		public Type PermissionType {get { return permissionType; } }
+		// Properties
+		public string PermissionState
+		{
+			get { return permissionState; }
+		}
+
+		public Type PermissionType
+		{
+			get { return permissionType; }
+		}
 
 		// Constructors
-		public SecurityException(){}
-		public SecurityException(string message) 
-			: base (message){}
-		protected SecurityException(SerializationInfo info, StreamingContext context) 
-			: base (info, context) {}
-		public SecurityException(string message, Exception inner) 
-			: base (message, inner) {}
-		public SecurityException(string message, Type type) 
+		public SecurityException ()
+			: base (Locale.GetText ("A security error has been detected."))
+		{
+		}
+
+		public SecurityException (string message) 
+			: base (message)
+		{
+		}
+		
+		protected SecurityException (SerializationInfo info, StreamingContext context) 
+			: base (info, context)
+		{
+			permissionState = info.GetString ("permissionState");
+		}
+		
+		public SecurityException (string message, Exception inner) 
+			: base (message, inner)
+		{
+		}
+		
+		public SecurityException (string message, Type type) 
 			:  base (message) 
 		{
 			permissionType = type;
 		}
-		public SecurityException(string message, Type type, string state) 
+		
+		public SecurityException (string message, Type type, string state) 
 			: base (message) 
 		{
 			permissionType = type;
 			permissionState = state;
 		}
 
+		// Methods
+		public override void GetObjectData (SerializationInfo info, StreamingContext context)
+		{
+			base.GetObjectData (info, context);
+			info.AddValue ("PermissionState", permissionState);
+		}
+
+		public override string ToString ()
+		{
+			return permissionType.FullName + ": " + permissionState;
+		}
 	}
-}
+}