vendredi 27 octobre 2017

Use different Classes in a method

I have different Model classes which I will use with a master class. Every Model class have the same method "Change", but specific properties. The properties can be called by reflection.

Now I want to use every class with a generic string, because the model to use is stored in a database.

This is the working non generic code:

var inter = default(DDS.Model.Classname);
inter = new Master().DoSomeWhat<DDS.Model.Classname>(variableA)

Now I want to write the Classname generic like that:

Type stringClass = Type.GetType("DDS.Model.Classname");
var inter = default(stringClass);
inter = new Master().DoSomeWhat<stringClass>(variableA)

The error I got is "stringClass is variable, but is used like type" What can I do here?

Thank you in advanced. Nu





Aucun commentaire:

Enregistrer un commentaire