Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions UnitTests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,38 @@ public static void ParseTest()
Assert.IsNotNull(o);
}

public struct NullableEnumStruct
{
public enumt? P1;
public enumt? P2;
public enumt P3;

public override string ToString()
{
return String.Format("{{P1={{{0}}}, P2={{{1}}}, P3={{{2}}}}}", P1, P2, P3);
}

public NullableEnumStruct(enumt? p1, enumt? p2, enumt p3)
{
P1 = p1;
P2 = p2;
P3 = p3;
}
}

[Test]
public static void NullableEnumTest()
{
var r = new NullableEnumStruct(enumt.B, null, enumt.C);

var s = BJSON.ToBJSON(r);
var o = BJSON.ToObject(s);

Assert.IsNotNull(o);
Assert.IsInstanceOf(r.GetType(), o);
Assert.AreEqual(r, o);
}

[Test]
public static void StringListTest()
{
Expand Down
2 changes: 2 additions & 0 deletions fastBinaryJSON/BJSON.cs
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,8 @@ private NameValueCollection CreateNV(Dictionary<string, object> d)
private object CreateEnum(Type pt, object v)
{
// FEATURE : optimize create enum
if (pt.IsGenericType && Reflection.Instance.GetGenericTypeDefinition(pt) == typeof(Nullable<>))
pt = Reflection.Instance.GetGenericArguments(pt)[0];
#if !SILVERLIGHT
return Enum.Parse(pt, v.ToString());
#else
Expand Down
4 changes: 2 additions & 2 deletions fastBinaryJSON/Reflection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ private myPropInfo CreateMyProp(Type t, string name)
else if (t == typeof(string)) d_type = myPropInfoType.String;
else if (t == typeof(bool) || t == typeof(bool?)) d_type = myPropInfoType.Bool;
else if (t == typeof(DateTime) || t == typeof(DateTime?)) d_type = myPropInfoType.DateTime;
else if (t.IsEnum) d_type = myPropInfoType.Enum;
else if (GetChangeType(t).IsEnum) d_type = myPropInfoType.Enum;
else if (t == typeof(Guid) || t == typeof(Guid?)) d_type = myPropInfoType.Guid;
else if (t == typeof(StringDictionary)) d_type = myPropInfoType.StringDictionary;
else if (t == typeof(NameValueCollection)) d_type = myPropInfoType.NameValue;
Expand Down Expand Up @@ -365,7 +365,7 @@ private myPropInfo CreateMyProp(Type t, string name)

private Type GetChangeType(Type conversionType)
{
if (conversionType.IsGenericType && conversionType.GetGenericTypeDefinition().Equals(typeof(Nullable<>)))
if (conversionType.IsGenericType && conversionType.GetGenericTypeDefinition() == typeof(Nullable<>))
return Reflection.Instance.GetGenericArguments(conversionType)[0];

return conversionType;
Expand Down