mercredi 25 décembre 2019

Create instance of private class and set read only property

I need to test a public method in my public class, however the input to the method is a private class. So I need to create an instance of this private class to make a proper test og the my method.

This private class has a field set by the constructor and then a readonly property defined by expression-bodied member, which extract some information from the field set by the constructor.

I managed to create an instance of the private class with reflection. I am now trying to get the backfield to set the value of this property. However when I get the backfield, it returns null. Specially when I try to set the value of the backing field with list of string, it gives me a null reference exception.

It is possible to do, what I am trying to do?





Aucun commentaire:

Enregistrer un commentaire