Get nested property values through reflection C#

后端 未结 2 1974
梦谈多话
梦谈多话 2020-12-21 19:31

I have following code.

Classes:

public class AlloyDock
{
    public int Left { get; set; }
    public int Right { get; set; }
}

pub         


        
2条回答
  •  一个人的身影
    2020-12-21 20:32

    The problem is with this expression:

    leafProperty.GetValue(obj, null)
    

    You are passing the root object in to get the leaf property. As you process each property you need to get its value and then call GetValue against it.

提交回复
热议问题