Fix calling constructors with ref and in parameters (#1728)

This commit is contained in:
James Newton-King
2018-05-29 10:46:51 +12:00
committed by GitHub
parent 42ee730f3a
commit 6dd352c490
7 changed files with 245 additions and 2 deletions
@@ -47,6 +47,33 @@ namespace Newtonsoft.Json.Tests.Utilities
[TestFixture]
public class ExpressionReflectionDelegateFactoryTests : TestFixtureBase
{
[Test]
public void ConstructorWithInString()
{
ConstructorInfo constructor = TestReflectionUtils.GetConstructors(typeof(InTestClass)).Single(c => c.GetParameters().Count() == 1);
var creator = ExpressionReflectionDelegateFactory.Instance.CreateParameterizedConstructor(constructor);
object[] args = new object[] { "Value" };
InTestClass o = (InTestClass)creator(args);
Assert.IsNotNull(o);
Assert.AreEqual("Value", o.Value);
}
[Test]
public void ConstructorWithInStringAndBool()
{
ConstructorInfo constructor = TestReflectionUtils.GetConstructors(typeof(InTestClass)).Single(c => c.GetParameters().Count() == 2);
var creator = ExpressionReflectionDelegateFactory.Instance.CreateParameterizedConstructor(constructor);
object[] args = new object[] { "Value", true };
InTestClass o = (InTestClass)creator(args);
Assert.IsNotNull(o);
Assert.AreEqual("Value", o.Value);
Assert.AreEqual(true, o.B1);
}
[Test]
public void ConstructorWithRefString()
{