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{
   //
   }
3
  • Normally such question should be duplicate of stackoverflow.com/questions/721870/…, but it sounds like you want to change routing somehow rather than just create generic type... Some clarification of exact problem may help. Commented Dec 11, 2015 at 6:18
  • Hey edited my question, its not about string to class converstion Commented Dec 11, 2015 at 6:36
  • 1
    What you are looking for could be possible - bing.com/search?q=c%23+webapi+generics+controller gives 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). Commented Dec 11, 2015 at 6:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.