UPDATE: Didn't give a great example. Hopefully it's better now.
Is there a better way than this:
(typeof(TRepository) == typeof(UserClass))
Here's the use in writing:
public static IBaseRepository<TClass> GetRepository<TClass>() where TClass : IDataEntity
{
IBaseRepository<TClass> repository = null;
if (typeof(TClass) == typeof(UserClass))
{
repository = (IBaseRepository<TClass>)new UserClassRepository();
}
if (typeof(TClass) == typeof(PostClass))
{
repository = (IBaseRepository<TClass>)new PostClassRepository();
}
return repository;
}
If something like this is run a lot, I hope there's better way than running typeof a bunch of times.