Browse Source

2009-12-14 Atsushi Enomoto <[email protected]>

	* TypeMap.cs : handle [Serializable] objects such as KeyValuePair<,>
	  like we do in 2.0. Removed previous workarounds. (Do not serialize
	  and deserialize nonpublic members in "default" mappings.)


svn path=/trunk/mcs/; revision=148364
Atsushi Eno 16 years ago
parent
commit
0ede800ea0

+ 6 - 0
mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/ChangeLog

@@ -1,3 +1,9 @@
+2009-12-14  Atsushi Enomoto  <[email protected]>
+
+	* TypeMap.cs : handle [Serializable] objects such as KeyValuePair<,>
+	  like we do in 2.0. Removed previous workarounds. (Do not serialize
+	  and deserialize nonpublic members in "default" mappings.)
+
 2009-12-11  Chris Toshok  <[email protected]>
 
 	* TypeMap.cs (CreateDefaultTypeMap): only include non-public

+ 2 - 24
mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/TypeMap.cs

@@ -58,11 +58,9 @@ namespace System.Runtime.Serialization.Json
 			if (atts.Length == 1)
 				return CreateTypeMap (type, (DataContractAttribute) atts [0]);
 
-#if !NET_2_1
 			atts = type.GetCustomAttributes (typeof (SerializableAttribute), false);
 			if (atts.Length == 1)
 				return CreateTypeMap (type, null);
-#endif
 
 			if (IsPrimitiveType (type))
 				return null;
@@ -84,28 +82,9 @@ namespace System.Runtime.Serialization.Json
 			var l = new List<TypeMapMember> ();
 			foreach (var fi in type.GetFields ())
 				l.Add (new TypeMapField (fi, null));
-
-			PropertyInfo[] properties;
-
-			// FIXME: this hack for property visibility
-			// emulates some of the special case code MS
-			// has.  a stack trace seen in testing showed
-			// a method called
-			// ReadKeyValuePairOfstringstringFromJson, so
-			// presumably they're dynamically creating
-			// methods to deserialize certain (possibly
-			// all generic?) types from json.
-
-			// see DataContractJsonSerializerTest.TestNonpublicDeserialization.
-			if (type == typeof (KeyValuePair<,>))
-				properties = type.GetProperties (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
-			else 
-				properties = type.GetProperties ();
-
-			foreach (var pi in properties) {
+			foreach (var pi in type.GetProperties ())
 				if (pi.CanRead && pi.CanWrite)
 					l.Add (new TypeMapProperty (pi, null));
-			}
 			l.Sort ((x, y) => x.Order != y.Order ? x.Order - y.Order : String.Compare (x.Name, y.Name, StringComparison.Ordinal));
 			return new TypeMap (type, null, l.ToArray ());
 		}
@@ -160,7 +139,7 @@ namespace System.Runtime.Serialization.Json
 				}
 			}
 
-			members.Sort (delegate (TypeMapMember m1, TypeMapMember m2) { return m1.Order - m2.Order; });
+			members.Sort (delegate (TypeMapMember m1, TypeMapMember m2) { return m1.Order != m2.Order ? m1.Order - m2.Order : String.CompareOrdinal (m1.Name, m2.Name); });
 			return new TypeMap (type, dca == null ? null : dca.Name, members.ToArray ());
 		}
 
@@ -299,7 +278,6 @@ namespace System.Runtime.Serialization.Json
 
 		public override void SetMemberValue (object owner, object value)
 		{
-			Console.Error.WriteLine ("SetMemberValue ({0},{1}", property, value);
 			property.SetValue (owner, value, null);
 		}
 	}