-Derp
This commit is contained in:
@@ -43,6 +43,20 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class DynamicConcreteTests : TestFixtureBase
|
public class DynamicConcreteTests : TestFixtureBase
|
||||||
{
|
{
|
||||||
|
public class DynamicConcreteContractResolver : DefaultContractResolver
|
||||||
|
{
|
||||||
|
protected override JsonContract CreateContract(Type objectType)
|
||||||
|
{
|
||||||
|
JsonContract contract = base.CreateContract(objectType);
|
||||||
|
|
||||||
|
// create a dynamic mock object for interfaces or abstract classes
|
||||||
|
if (contract.CreatedType.IsInterface || contract.CreatedType.IsAbstract)
|
||||||
|
contract.DefaultCreator = () => DynamicConcrete.GetInstanceFor(contract.CreatedType);
|
||||||
|
|
||||||
|
return contract;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void UseDynamicConcreteIfTargetObjectTypeIsAnInterfaceWithNoBackingClass()
|
public void UseDynamicConcreteIfTargetObjectTypeIsAnInterfaceWithNoBackingClass()
|
||||||
{
|
{
|
||||||
@@ -100,18 +114,6 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
bool FuncWithValType_2();
|
bool FuncWithValType_2();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DynamicConcreteContractResolver : DefaultContractResolver
|
|
||||||
{
|
|
||||||
protected override JsonContract CreateContract(Type objectType)
|
|
||||||
{
|
|
||||||
JsonContract contract = base.CreateContract(objectType);
|
|
||||||
if (contract.CreatedType.IsAbstract || contract.CreatedType.IsInterface)
|
|
||||||
contract.DefaultCreator = () => DynamicConcrete.GetInstanceFor(contract.CreatedType);
|
|
||||||
|
|
||||||
return contract;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates run-time backing types for abstract classes and interfaces
|
/// Creates run-time backing types for abstract classes and interfaces
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user