Unconstrain

Enum and Delegate generic constrainsts for C#


Keywords
generics, constraint, delegate, C#, enum
Install
Install-Package Unconstrain -Version 0.1.3

Documentation

Unconstrain

Enables uage of enum and delegate as generic constraints in C#.

How to use?

  • Install from NuGet: Install-Package Unconstrain.
    It's just a Development dependency that would automatically configure your project.

How does it Work?

  • User maps enum and delegate constraints to IEnumConstraint and DelegateConstraint respectively.
  • Project is compiled by csc.exe.
  • ILDASM is called on the compiled DLL file to generate IL.
  • References to IEnumConstraint and DelegateConstraint are mapped back to System.Enum and System.Delegate in the IL.
  • ILASM is used to compile the modified IL into DLL.
  • Any remaining .il, .res and .mdb files are deleted.

Troubleshooting

It may happen that the package isn't able to find ILDASM or ILASM, in that case proceed as follows: (Also, let me know if you have better workarounds)

  • Goto packages/Unconstrain.*/build folder in your project.
  • Open Unconstrain.targets in Notepad or any other suitable editor.
  • Find the <ILDASM> tag. Replace its contents with the path to ildasm.exe on your system.
  • Do the same (if required) with <ILASM> tag with path to ilasm.exe.