0

In the below code how to set generic 'T' as a class dynamically?

Currently am redirecting all the API request to a single web api called "dummy" by routing.

So url's like

"api/person" then take person as class 
"api/students" then take students as class

So here how to pass person or students or any other dynamic class in GenericDataController T.

     //web api controller 
      public class dummyController :GenericDataController<T> 
     {
        //
     }

GenericData web api

    public class GenericDataController<T> :ApiController where T : class
    {

    private IGenericDataService _dataService;
    public GenericDataController(IGenericDataService dataService)
    {
        _dataService = dataService;
    }

    // GET: api/GenericData
    public IEnumerable<T> Get()
    {

        return _dataService.Get<T>();
    }
   }

In my model i have all class models

  public class Person{
   //
   }
  public class Student{
   //
   }
CristiC
  • 22,068
  • 12
  • 57
  • 89
Deepak Saralaya
  • 457
  • 4
  • 12
  • Normally such question should be duplicate of http://stackoverflow.com/questions/721870/how-can-i-get-generic-type-from-string-representation, but it sounds like you want to change routing somehow rather than just create generic type... Some clarification of exact problem may help. – Alexei Levenkov Dec 11 '15 at 06:18
  • Hey edited my question, its not about string to class converstion – Deepak Saralaya Dec 11 '15 at 06:36
  • 1
    What you are looking for could be possible - https://www.bing.com/search?q=c%23+webapi+generics+controller gives http://stackoverflow.com/a/20629883/477420 which may point you to direction to implement what you are looking for... (There probably exact duplicate too - you may want to search for it). – Alexei Levenkov Dec 11 '15 at 06:44

0 Answers0