c# - convert class string to class -


I have the code below in my ASP.NET app, I would like to change the converter name variable For class and this is the FillRequest & lt; T & gt; Pass in the method. Is this possible?

  var converter name = HttpContext.Current.Items ["converter name"] as string; FillRequest & LT; Web2ImageEntity & gt; (Request.Params);   

Alternatively I can

  var converter name = HttpContext.Current.Items ["converter name"] as string; If (converter name == "web 2 image entity") filwist & lt; Web2ImageEntity & gt; (Request para);   

But I have around 20 unit squares and I want to find a way to write code.

This will not be possible because the generic type must be specified at compile time. What you can do is to change the FillRequest method to be something like below and then use reflection to do the desired work

  FillRequest (string [] parameter, type converter) {// Type the object from the converter and call the req method}   

Or take an interface to filarize

  FillRequest (string [] parameter, iconwise c ) {// ways to convert call c}   

Calling it something like this Oga:

  var type = Type.GetType (converterName); FillRequest (Request.Params, (IConverter) Activator.CreateInstance (type));    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -