How can I use interface as a C# generic type constraint?
The closest you can do (except for your base-interface approach) is "where T : class
", meaning reference-type. There is no syntax to mean "any interface".
This ("where T : class
") is used, for example, in WCF to limit clients to service contracts (interfaces).
I know this is a bit late but for those that are interested you can use a runtime check.
typeof(T).IsInterface
No, actually, if you are thinking class
and struct
mean class
es and struct
s, you're wrong. class
means any reference type (e.g. includes interfaces too) and struct
means any value type (e.g. struct
, enum
).