lundi 15 juin 2015

Convert string into nested property reference in C#

I have found a few reflection articles but I am still stumped. Here is the situation: a) There is a class with a variety of fields, some of which are themselves subclass references. In total, this class is probably nested to five levels. b) I instantiate an object from this parent class which populates every field at every level. c) I would like to have an nUnit TestCase / data-driven test case that takes a string as an argument which is converted into a reference into the field. I would then set the field to NULL or "" for the purposes of seeing how my API responds to a serialized JSON object created from the class, missing a specific field.

For example: "a.b.c.d" is converted into myInstantiatedObject.a.b.c.d = null;

I assume I need a recursive function to do this, but I am confused as to how to proceed.





Aucun commentaire:

Enregistrer un commentaire