Skip to content

Commit

Permalink
- Fixed #206
Browse files Browse the repository at this point in the history
Signed-off-by: rpgmaker <olamide.bakre@gmail.com>
  • Loading branch information
rpgmaker committed Feb 14, 2019
1 parent e473ac4 commit 058d1b1
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 8 deletions.
15 changes: 7 additions & 8 deletions NetJSON.Tests/SerializeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,7 @@ public void CanDeserializeObjectWithDefaultValueOfFalseBoolean()

private static readonly NetJSONSettings Settings = new NetJSONSettings { DateFormat = NetJSONDateFormat.ISO, TimeZoneFormat = NetJSONTimeZoneFormat.Utc };

//[TestMethod]
[TestMethod]
public void HandlesNullable()
{
var nullable = new NullableEntity { Id = Guid.NewGuid(), Value = new ValueObject { Value = "Test" } };
Expand Down Expand Up @@ -1373,10 +1373,9 @@ private static bool CanSerialize(MemberInfo memberInfo)
return true;
}

//private static readonly NetJSONSettings Settings = new NetJSONSettings { DateFormat = NetJSONDateFormat.ISO, TimeZoneFormat = NetJSONTimeZoneFormat.Utc };
private static readonly Random Random = new Random();

[TestMethod] // Fails: not deserialised
[TestMethod]
public void EventStructTest()
{
var e = new EventStruct(Guid.NewGuid(), new PayloadStruct(Guid.NewGuid().ToString("n")), Random.Next(), DateTimeOffset.UtcNow);
Expand All @@ -1389,7 +1388,7 @@ public void EventStructTest()
Assert.AreEqual(e.Created, d.Created);
}

[TestMethod] // Fails: System.AccessViolationException at NetJSON.SetterPropertyValue<EventStructWithPrivateSetters>(EventStructWithPrivateSetters instance, object value, System.Reflection.MethodInfo methodInfo)
[TestMethod]
public void EventStructWithPrivateSettersTest()
{
var e = new EventStructWithPrivateSetters(Guid.NewGuid(), new PayloadStructWithPrivateSetter(Guid.NewGuid().ToString("n")), Random.Next(), DateTimeOffset.UtcNow);
Expand All @@ -1402,7 +1401,7 @@ public void EventStructWithPrivateSettersTest()
Assert.AreEqual(e.Created, d.Created);
}

[TestMethod] // Fails: not deserialised
[TestMethod]
public void EventStructWithReadOnlyBackingFieldsTest()
{
var e = new EventStructWithReadOnlyBackingFields(Guid.NewGuid(), new PayloadStructWithReadOnlyBackingField(Guid.NewGuid().ToString("n")), Random.Next(), DateTimeOffset.UtcNow);
Expand All @@ -1415,7 +1414,7 @@ public void EventStructWithReadOnlyBackingFieldsTest()
Assert.AreEqual(e.Created, d.Created);
}

[TestMethod] // Fails: not deserialised
[TestMethod]
public void EventClassTest()
{
var e = new EventClass(Guid.NewGuid(), new PayloadClass(Guid.NewGuid().ToString("n")), Random.Next(), DateTimeOffset.UtcNow);
Expand All @@ -1428,7 +1427,7 @@ public void EventClassTest()
Assert.AreEqual(e.Created, d.Created);
}

[TestMethod] // Passes
[TestMethod]
public void EventClassWithPrivateSettersTest()
{
var e = new EventClassWithPrivateSetters(Guid.NewGuid(), new PayloadClassWithPrivateSetter(Guid.NewGuid().ToString("n")), Random.Next(), DateTimeOffset.UtcNow);
Expand All @@ -1441,7 +1440,7 @@ public void EventClassWithPrivateSettersTest()
Assert.AreEqual(e.Created, d.Created);
}

[TestMethod] // Fails: not deserialised
[TestMethod]
public void EventClassWithReadOnlyBackingFieldsTest()
{
var e = new EventClassWithReadOnlyBackingFields(Guid.NewGuid(), new PayloadClassWithWithReadOnlyBackingField(Guid.NewGuid().ToString("n")), Random.Next(), DateTimeOffset.UtcNow);
Expand Down
10 changes: 10 additions & 0 deletions NetJSON/NetJSON.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4876,6 +4876,11 @@ private static MethodInfo GenerateGetClassOrDictFor(TypeBuilder typeBuilder, Typ
il.Emit(OpCodes.Ldnull);
}

if (isNullable)
{
il.Emit(OpCodes.Newobj, _nullableType.MakeGenericType(type).GetConstructor(new[] { type }));
}

il.Emit(OpCodes.Ret);

il.MarkLabel(isNullObjectLabel);
Expand Down Expand Up @@ -5079,6 +5084,11 @@ private static MethodInfo GenerateGetClassOrDictFor(TypeBuilder typeBuilder, Typ
}else
il.Emit(OpCodes.Ldloc, obj);
}

if (isNullable)
{
il.Emit(OpCodes.Newobj, _nullableType.MakeGenericType(type).GetConstructor(new[] { type }));
}
},
beginIndexIf: (msil, current) => {
il.Emit(OpCodes.Ldloc, current);
Expand Down
Binary file modified NetJSON/lib/net35/NetJSON.dll
Binary file not shown.
Binary file modified NetJSON/lib/net40/NetJSON.dll
Binary file not shown.
Binary file modified NetJSON/lib/net462/NetJSON.dll
Binary file not shown.
Binary file modified NetJSON/lib/net472/NetJSON.dll
Binary file not shown.
Binary file modified NetJSON/lib/netstandard1.6/NetJSON.Core.dll
Binary file not shown.
Binary file modified NetJSON/lib/netstandard2.0/NetJSON.dll
Binary file not shown.

0 comments on commit 058d1b1

Please sign in to comment.