Generic Programming
Write type-safe code once, apply it to any data type. Generics eliminate code duplication while preserving full compile-time type checking — no casting, no runtime surprises.
📖 The Concept
GET/api/Generic/demo
What it is
Generics allow you to define classes, methods, and interfaces with a placeholder type
T resolved at compile time. The compiler enforces type safety without requiring separate implementations for each type.
In this codebase
The Generic CRUD API uses one controller and service to handle any entity type via reflection + generics. Adding a new entity requires only a class definition — no new controller, no new routes.
Code example
// One method handles any type T
public class GenericRepository<T>
where T : class
{
public IEnumerable<T> GetAll()
=> _context.Set<T>().ToList();
}
⚡ Live Demo
Select an entity type and run the demo. The same generic API method handles all entity types — watch the response shape change based on your selection.
Entity Type
API Response
Awaiting request
Tap "Run Demo" to fire the API call and see the response...