0

My requirement is I have to read data from one service and push this data into different tables(t1,t2,t3 or many more)

For this I created one table to map data field from service to table name and field name.

Eg: fname belongs to user table first name field

Now I am looping through this and creating objects before hand and assigning values from data returned from service by using switch case

T1 objt1; T2 objT2; T3 objT3; For loop mapping data

   Switch(mapping data field)
    Case "T1": 

    var obj1 =          entity.GetType().GetProperty(propertyName);
    Obj1.SetValue(entity, data.Substring(1, data.Length - 2) == "Y", null);
     break;
      Case "T2":
      // code 

break;

Now how do we do this without creating instance of T1, T2 before hand and by not using switch case for every table type

We cannot use System.activator.createinstance because of performance issues with it

I want some solution using dictionary, so that we need not create instances of every class created

  • Is `T1` a generic type parameter for a function? Or an actual class that already exists? Is it in the same assembly? Are you wanting instantiate an existing class based off a string class name, or actually create a new class entirely at runtime? – Jeff B Nov 19 '15 at 19:43
  • 2
    Depending on what your question is, check out either [Create an instance of a class from a string](http://stackoverflow.com/q/223952/945456) or [Dynamically create a class in C#](http://stackoverflow.com/q/3862226/945456). – Jeff B Nov 19 '15 at 19:45
  • Jeff, T1 is a class which already exists. – FirstRanker. com Nov 20 '15 at 07:28
  • Jeff, instead of using activator, I wanted some solution using dictionary without creating object for every class. – FirstRanker. com Nov 20 '15 at 07:32
  • Sorry, I don't really understand what you're asking. Could you perhaps [edit](https://stackoverflow.com/posts/33812915/edit) you question to provide more detail with an (almost) working example highlighting specifically the desired behavior and where you are having problems getting it to work? If that's not possible, perhaps just do you best to describe the scenario and give us desired input and output and others in the community can recommend a good approach. – Jeff B Nov 20 '15 at 20:16

0 Answers0