-Tests
This commit is contained in:
@@ -205,6 +205,37 @@ namespace Newtonsoft.Json.Tests.Utilities
|
||||
MyStruct myStruct2 = creator2.Invoke();
|
||||
Assert.AreEqual(0, myStruct2.IntProperty);
|
||||
}
|
||||
|
||||
public struct TestStruct
|
||||
{
|
||||
public TestStruct(int i)
|
||||
{
|
||||
Value = i;
|
||||
}
|
||||
|
||||
public int Value { get; }
|
||||
}
|
||||
|
||||
public static TestStruct StructMethod(TestStruct s)
|
||||
{
|
||||
return new TestStruct(s.Value + s.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateStructMethodCall()
|
||||
{
|
||||
MethodInfo methodInfo = typeof(DynamicReflectionDelegateFactoryTests).GetMethod(nameof(StructMethod), new[] { typeof(TestStruct) });
|
||||
|
||||
Assert.IsNotNull(methodInfo);
|
||||
|
||||
MethodCall<object, object> call = DynamicReflectionDelegateFactory.Instance.CreateMethodCall<object>(methodInfo);
|
||||
|
||||
object result = call(null, new TestStruct(123));
|
||||
Assert.IsNotNull(result);
|
||||
|
||||
TestStruct s = (TestStruct)result;
|
||||
Assert.AreEqual(246, s.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -374,6 +374,37 @@ namespace Newtonsoft.Json.Tests.Utilities
|
||||
MyStruct myStruct2 = creator2.Invoke();
|
||||
Assert.AreEqual(0, myStruct2.IntProperty);
|
||||
}
|
||||
|
||||
public struct TestStruct
|
||||
{
|
||||
public TestStruct(int i)
|
||||
{
|
||||
Value = i;
|
||||
}
|
||||
|
||||
public int Value { get; }
|
||||
}
|
||||
|
||||
public static TestStruct StructMethod(TestStruct s)
|
||||
{
|
||||
return new TestStruct(s.Value + s.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateStructMethodCall()
|
||||
{
|
||||
MethodInfo methodInfo = typeof(ExpressionReflectionDelegateFactoryTests).GetMethod(nameof(StructMethod), new[] { typeof(TestStruct) });
|
||||
|
||||
Assert.IsNotNull(methodInfo);
|
||||
|
||||
MethodCall<object, object> call = ExpressionReflectionDelegateFactory.Instance.CreateMethodCall<object>(methodInfo);
|
||||
|
||||
object result = call(null, new TestStruct(123));
|
||||
Assert.IsNotNull(result);
|
||||
|
||||
TestStruct s = (TestStruct)result;
|
||||
Assert.AreEqual(246, s.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,6 @@ namespace Newtonsoft.Json.Utilities
|
||||
|
||||
LocalBuilder localConvertible = generator.DeclareLocal(typeof(IConvertible));
|
||||
LocalBuilder localObject = generator.DeclareLocal(typeof(object));
|
||||
int localVariableCount = 2;
|
||||
|
||||
for (int i = 0; i < args.Length; i++)
|
||||
{
|
||||
@@ -140,11 +139,9 @@ namespace Newtonsoft.Json.Utilities
|
||||
}
|
||||
|
||||
generator.Emit(OpCodes.Ldloca_S, localVariable);
|
||||
|
||||
localVariableCount++;
|
||||
}
|
||||
else if (parameterType.IsValueType())
|
||||
{
|
||||
{
|
||||
generator.PushArrayInstance(argsIndex, i);
|
||||
generator.Emit(OpCodes.Stloc_S, localObject);
|
||||
|
||||
@@ -170,7 +167,6 @@ namespace Newtonsoft.Json.Utilities
|
||||
if (parameterType.IsPrimitive())
|
||||
{
|
||||
// for primitive types we need to handle type widening (e.g. short -> int)
|
||||
|
||||
MethodInfo toParameterTypeMethod = typeof(IConvertible)
|
||||
.GetMethod("To" + parameterType.Name, new[] { typeof(IFormatProvider) });
|
||||
|
||||
@@ -209,7 +205,6 @@ namespace Newtonsoft.Json.Utilities
|
||||
|
||||
// parameter finished, we out!
|
||||
generator.MarkLabel(finishedProcessingParameter);
|
||||
localVariableCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -50,8 +50,8 @@
|
||||
return true;
|
||||
}
|
||||
|
||||
int fromMask = 0,
|
||||
toMask = 0;
|
||||
int fromMask = 0;
|
||||
int toMask = 0;
|
||||
|
||||
for (int i = 0; i < PrimitiveTypes.Length; i++)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user