I have class with private readonly field
public class Bar
{
private readonly ICollection<Foo> somePrivateCollection = new HashSet<Foo>();
public IEnumerable<Foo> SomePublicCollection => somePrivateCollection;
public int z;
}
And
public class Foo
{
public int x;
}
I can set this field by GetField => SetValue
[Fact]
public void someTest()
{
var fooObjects = new Faker<Foo>().Generate(1);
var barObject = new Faker<Bar>().RuleFor(t => t.z, f => f.Random.Int())
.Generate();
barObject.GetType()
.GetField("somePrivateCollection", System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Instance)
.SetValue(barObject, fooObjects);
}
But how can I set this field using same style
var barObject = new Faker<Bar>().RuleFor(t => t.z, f => f.Random.Int())
.RuleSetter("somePrivateCollection",fooObjects)
.Generate();
if difference between public and private field just in 1 letter