You could try and do this through reflection.
public ObservableCollection<T> GetAll<T>()
{
var typeName = typeof(T).FullName;
var indexOfDot = typeName.LastIndexOf('.');
var newTypeName = typeName.SubString(0, indexOfDot) + '.' + typeName.SubString(indexOfDot + 1);
var newType = Type.GetType(newTypeName);
var methodTypes = new [] { typeof(T), newType };
var method = GetType().GetMethod("GetAll");
var typedMethod = method.MakeGenericMethod(methodTypes);
return (ObservableCollection<T>) typedMethod.Invoke(this, new object[0]);
}
Not pretty, but should do the job and does is generically.
The only caveat the current way is that the GetAll
method is overloaded by generic parameters, so it may not get you the right method, or fail because there are two. I'll have a look if the right one can be indicated.