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).
More Related Contents:
- Is there a constraint that restricts my generic method to numeric types?
- Solution for overloaded operator constraint in .NET generics
- Generic constraints, where T : struct and where T : class
- C# Generics won’t allow Delegate Type Constraints
- Is there a C# generic constraint for “real number” types? [duplicate]
- Curiously Recurring Template Pattern and generics constraints (C#)
- Why use generic constraints in C#
- Why does this generic constraint compile when it seems to have a circular reference
- Is there a generic constraint I could use for the + operator?
- Creating a Math library using Generics in C#
- Restricting a generic type parameters to have a specific constructor
- How can I write a generic container class that implements a given interface in C#?
- How to constrain generic type to must have a construtor that takes certain parameters?
- How does a generic constraint prevent boxing of a value type with an implicitly implemented interface?
- Can you use “where” to require an attribute in c#?
- Pass An Instantiated System.Type as a Type Parameter for a Generic Class
- How to get the type of T from a member of a generic class or method
- Check if a class is derived from a generic class
- Passing dynamic object to C# method changes return type
- How to call generic method with a given Type object? [duplicate]
- Dynamically Create a generic type for template
- Why can’t I assign a List to a List?
- Console.WriteLine and generic List
- Mocking generic methods in Moq without specifying T
- Filtering out values from a C# Generic Dictionary
- Casting array to IEnumerable
- Why is it impossible to declare extension methods in a generic static class?
- Hashtable to Dictionary syncroot .
- Generic list of generic objects
- Generic Web Api controller to support any model