vendredi 27 janvier 2017

How to invoke protected method of an abstract method by means of Reflection?

I'm trying to write a unit test for an abstract class. More specifically, I have a class like

public abstract class MyAbstractClass
{
    // ... 
    private Something _myPrivateVariable; 
    // ...
    protected void MyProtectedMethod(string[] names) { // ... }
    // ... 
}

and I want to call MyProtectedVoid with parameters and then verify that _myPrivateVariable was set to a particular value.

I know how to invoke a private method of an instance of a class using GetMethod like in How do I use reflection to invoke a private method?, but I don't know how to do this type of thing with an abstract class considering that I can't create an instance of it.





Aucun commentaire:

Enregistrer un commentaire