Fix calling constructors with ref and in parameters (#1728)
This commit is contained in:
@@ -44,9 +44,53 @@ namespace Newtonsoft.Json.Tests.Utilities
|
||||
}
|
||||
}
|
||||
|
||||
public class InTestClass
|
||||
{
|
||||
public string Value { get; }
|
||||
public bool B1 { get; }
|
||||
|
||||
public InTestClass(in string value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public InTestClass(in string value, in bool b1)
|
||||
: this(in value)
|
||||
{
|
||||
B1 = b1;
|
||||
}
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class LateboundReflectionDelegateFactoryTests : TestFixtureBase
|
||||
{
|
||||
[Test]
|
||||
public void ConstructorWithInString()
|
||||
{
|
||||
ConstructorInfo constructor = TestReflectionUtils.GetConstructors(typeof(InTestClass)).Single(c => c.GetParameters().Count() == 1);
|
||||
|
||||
var creator = LateBoundReflectionDelegateFactory.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 = LateBoundReflectionDelegateFactory.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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user