We recently introduced a completely new data model which is different from our current model from the logical structure point of view. We also changed the language of the model from German to English, because we want to open the models structure as XML to our customer.
In order to be able to convert the model we implemented a explicit conversion which basically matches all properties from the different classes of the new model into our old model.
Like this:
private OldModel Convert(NewModel src)
{
var dst = new OldModel();
dst.Prop1 = src.SomeOtherProp
dst.Prop2 = Convert(src.ComplexProp);
//....
return dst;
}
Now we want to make sure, all of the properties of the new model are written into the old model for coverage and testing purposes. We also want to make sure we didn’t forget any property and also guarantee that for future model extensions, we don’t forget a property.
My idea would be to parse the codefile, extract all properties which are read from the new model, run over the new model with reflection compare them with the actual properties within it.
This solution feels not like a good one 🙂 Any suggestions?
I appreciate any help!
We finally decided to parse the codefile with regular expressions like this:
It will match methods like this
private static Namespace.ClassName Convert(Namespace.ClassName input)and will extract the methods body.Since the converter methods follow a simple structural pattern, it was easy to extract the information I needed.