Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class OracleRepository<T> : IRepository<T> where T : new()
- {
- public IQueryable<T> GetAll()
- {
- if (typeof(T) == typeof(Object1))
- {
- return (IQueryable<T>)DataAccess.GetAllObject1().AsQueryable();
- }
- if (typeof(T) == typeof(Object2))
- {
- return (IQueryable<T>)DataAccess.GetAllObject2().AsQueryable();
- }
- throw new NotImplementedException();
- }
- }
- private static readonly IDictionary<Type, Func<object>> Fetchers =
- new Dictionary<Type, Func<object>>();
- {
- (typeof(Object1), () => DataAccess.GetAllObject1().AsQueryable()),
- (typeof(Object2), () => DataAccess.GetAllObject2().AsQueryable()),
- // etc
- };
- public IQueryable<T> GetAll()
- {
- Func<object> func = Fetchers[typeof(T)];
- if (func == null)
- {
- throw new NotImplementedException();
- }
- return (IQueryable<T>) func();
- }
Add Comment
Please, Sign In to add comment