0

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

Nunzio
  • 76
  • 1
  • 7
  • The error is explaining exactly what is happening here: You are not using a type you are using a variable of a `Type`. Please refer to [this](https://stackoverflow.com/questions/4667981/c-sharp-use-system-type-as-generic-parameter), for further information. – Ian H. Oct 27 '17 at 23:30
  • You are using `stringClass`, a _variable_, as if it were a type identifier, in two different places. See each marked duplicate for existing answers that completely explain how to do what you want to do. – Peter Duniho Oct 28 '17 at 00:14
  • That works fine, thank you so much! – Nunzio Oct 28 '17 at 21:38

0 Answers0