You've already forked linux-packaging-mono
Imported Upstream version 3.8.0
Former-commit-id: 6a76a29bd07d86e57c6c8da45c65ed5447d38a61
This commit is contained in:
@@ -180,16 +180,20 @@ namespace System.Web.Script.Serialization
|
||||
return c.ConvertFrom (obj);
|
||||
}
|
||||
|
||||
/*
|
||||
* Take care of the special case whereas in JSON an empty string ("") really means
|
||||
* an empty value
|
||||
* (see: https://bugzilla.novell.com/show_bug.cgi?id=328836)
|
||||
*/
|
||||
if ((targetType.IsGenericType) && (targetType.GetGenericTypeDefinition() == typeof(Nullable<>)))
|
||||
{
|
||||
string s = obj as String;
|
||||
if (String.IsNullOrEmpty(s))
|
||||
if ((targetType.IsGenericType) && (targetType.GetGenericTypeDefinition () == typeof (Nullable<>))) {
|
||||
if (obj is String) {
|
||||
/*
|
||||
* Take care of the special case whereas in JSON an empty string ("") really means
|
||||
* an empty value
|
||||
* (see: https://bugzilla.novell.com/show_bug.cgi?id=328836)
|
||||
*/
|
||||
if(String.IsNullOrEmpty ((String)obj))
|
||||
return null;
|
||||
} else if (c.CanConvertFrom (typeof (string))) {
|
||||
TypeConverter objConverter = TypeDescriptor.GetConverter (obj);
|
||||
string s = objConverter.ConvertToInvariantString (obj);
|
||||
return c.ConvertFromInvariantString (s);
|
||||
}
|
||||
}
|
||||
|
||||
return Convert.ChangeType (obj, targetType);
|
||||
|
||||
@@ -1365,5 +1365,28 @@ namespace MonoTests.System.Web.Script.Serialization
|
||||
var ret2vad = (IDictionary<string,object>) ret2va [0];
|
||||
Assert.AreEqual ("subval", ret2vad ["subkey"], "#2.4");
|
||||
}
|
||||
|
||||
class ClassWithNullableEnum
|
||||
{
|
||||
public MyEnum? Value { get; set; }
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializeNullableEnum ()
|
||||
{
|
||||
var jsonValues = new Dictionary<string, MyEnum?> {
|
||||
{ "{\"Value\":0}", MyEnum.AAA},
|
||||
{ "{\"Value\":\"0\"}", MyEnum.AAA},
|
||||
{ "{\"Value\":null}", null}
|
||||
};
|
||||
|
||||
var ser = new JavaScriptSerializer ();
|
||||
|
||||
foreach (var kv in jsonValues)
|
||||
{
|
||||
var obj = ser.Deserialize<ClassWithNullableEnum> (kv.Key);
|
||||
Assert.AreEqual (kv.Value, obj.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user