You can restrict a type to a specific interface, but not to any arbitrary interface.
public T MyFunction<T>() where T : IMyInterface { return null; }
This will allow you to pass any object that implements this particular interface.
Edit:
Given your goals, from the comments, I personally will probably just run a check of execution:
public IEnumerable<T> LoadInterfaceImplementations<T>()
{
Type type = typeof(T);
if (!type.IsInterface)
throw new ArgumentException("The type must be an Interface");
}
source
share