Skip to content

71/AnyConstraint.Analyzer

Repository files navigation

AnyConstraint.Analyzer

A simple C# analyzer that suppresses the CS0702: "Constraint cannot be special class 'Delegate' / 'Enum' / '...' " error.

Installation

Simply install the NuGet package, and the analyzer will be automatically added to your project.

Install-Package AnyConstraint.Analyzer

Usage

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")]

How does it work?

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.

About

Analyzer that suppresses the CS0702 error, thus allowing any constraint to be used (including 'Delegate' and 'Enum').

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published