Author: kostat
Date: 2007-06-21 11:52:56 -0400 (Thu, 21 Jun 2007)
New Revision: 80487
Modified:
trunk/mcs/class/System.Web.Extensions/Test/System.Web.Script.Serialization/JavaScriptSerializerTest.cs
Log:
implement a CultureInfoConverter for testing
Modified:
trunk/mcs/class/System.Web.Extensions/Test/System.Web.Script.Serialization/JavaScriptSerializerTest.cs
===================================================================
---
trunk/mcs/class/System.Web.Extensions/Test/System.Web.Script.Serialization/JavaScriptSerializerTest.cs
2007-06-21 15:30:02 UTC (rev 80486)
+++
trunk/mcs/class/System.Web.Extensions/Test/System.Web.Script.Serialization/JavaScriptSerializerTest.cs
2007-06-21 15:52:56 UTC (rev 80487)
@@ -348,9 +348,11 @@
JavaScriptSerializer ser = new JavaScriptSerializer ();
List<JavaScriptConverter> list = new
List<JavaScriptConverter> ();
list.Add (new MyJavaScriptConverter ());
+ list.Add (new CultureInfoConverter ());
ser.RegisterConverters (list);
string result = ser.Serialize (new X [] { new X (), new
X () });
Assert.AreEqual ("{\"0\":1,\"1\":2}", result);
+ result = ser.Serialize
(Thread.CurrentThread.CurrentCulture);
}
[Test]
@@ -400,5 +402,28 @@
}
}
}
+
+ sealed class CultureInfoConverter : JavaScriptConverter
+ {
+ static readonly Type typeofCultureInfo = typeof
(CultureInfo);
+ public override IEnumerable<Type> SupportedTypes {
+ get { yield return typeofCultureInfo; }
+ }
+
+ public override object Deserialize (IDictionary<string,
object> dictionary, Type type, JavaScriptSerializer serializer) {
+ throw new NotSupportedException ();
+ }
+
+ public override IDictionary<string, object> Serialize
(object obj, JavaScriptSerializer serializer) {
+ CultureInfo ci = (CultureInfo)obj;
+ if (ci == null)
+ return null;
+ Dictionary<string, object> d = new
Dictionary<string, object> ();
+ d.Add ("name", ci.Name);
+ d.Add ("numberFormat", ci.NumberFormat);
+ d.Add ("dateTimeFormat", ci.DateTimeFormat);
+ return d;
+ }
+ }
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches