How can I use PrivateObject to access private members of both my class and its parent?

前端 未结 7 1995
逝去的感伤
逝去的感伤 2020-12-08 07:41

I\'m testing a class that is part of a hierarchy. I\'ve been setting up my test classes with the object under test, and a PrivateObject to allow access to that

7条回答
  •  青春惊慌失措
    2020-12-08 08:25

    I wanted to do same thing and I made this extension methods. Now it works well. My initial idea is from your post. Thank you!

    https://github.com/cactuaroid/PrivateObjectExtensions

    What it's doing basically is finding member owner by Type.GetFields() and Type.GetProperties() recursively, and then create PrivateObject (or PrivateType) as correct type to access the member.

提交回复
热议问题