1
class classD
{
  TestFunction(int classToSet)
  {
     var classAObj = new ClassA();
     var classType = getClassByParam(classToSet);
     classAObj.Method1<classType>(1);
  }
}
private Type getClassByParam(int classToSet)
{
   var classType = default(Type);
   switch(classToSet)
   {
      case 1 : classType = typeOf(classB);
      break;
      case 2 : classType = typeOf(classC);
      break;
   }
   return classType;
}
class ClassA
{
   public int Method1<TSource>(int t)
   {
       some action .. 
       return 1;
   } 
}
class classB
{
}
class classC
{
}

i am having generic method, whose type will be decided run time.

I got something which execute generic method using reflection of ClassA in Dynamically set generic type argument. But i don't want to use reflection of ClassA. instead i want to use object of classA.

Community
  • 1
  • 1
Hemant Malpote
  • 891
  • 13
  • 28

0 Answers0