vendredi 28 octobre 2016

How to set nested property value using FastMember

I get an exception when I try to set a nested member Property using FastMember. For example when having these classes

public class A
{
    public B First {get; set;}
}

public class B
{
    public string Second {get; set;}
}

and I want to set First.Second of an instance to "hello".

var b = new B{ Second = "some value here" }; var a = new A{ First = b };

var accessor = ObjectAccessor.Create(a); accessor["First.Second"] = value; // this does not work and gives ArgumentOutOfRangeException

I can't split it up into ["First"]["Second"] because I don't know the depth at this point. Is there a magical access for nested properties or do I have to split the hierarchy myself?





Aucun commentaire:

Enregistrer un commentaire