A simple C# analyzer that suppresses the CS0702: "Constraint cannot be special class 'Delegate' / 'Enum' / '...' " error.
Simply install the NuGet package, and the analyzer will be automatically added to your project.
Install-Package AnyConstraint.Analyzer
There is no usage. Having the analyzer referenced is enough. The following code should compile just fine:
public static void Invoke<TDelegate>(TDelegate del) where TDelegate : Delegate { ... }
public static void GetValues<T>(T @enum) where T : Enum { ... }
Nonetheless, an error will be shown in Visual Studio. To hide it from the 'Error List' panel, you can add the following code above your method:
[SuppressMessage("Compiler", "CS0702")]
Or, at the global level:
[assembly: SuppressMessage("Compiler", "CS0702")]
Using Ryder, the internal call to Binder.IsValidConstraintType
is replaced by a simple return true
statement, thus allowing any type to be used as a constraint.