Unconstrain
Enables uage of enum
and delegate
as generic constraints in C#.
How to use?
-
Install from NuGet:
Install-Package Unconstrain
.
It's just aDevelopment dependency
that would automatically configure your project.
How does it Work?
- User maps
enum
anddelegate
constraints toIEnumConstraint
andDelegateConstraint
respectively. - Project is compiled by
csc.exe
. -
ILDASM
is called on the compiledDLL
file to generateIL
. - References to
IEnumConstraint
andDelegateConstraint
are mapped back toSystem.Enum
andSystem.Delegate
in theIL
. -
ILASM
is used to compile the modifiedIL
intoDLL
. - 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 toildasm.exe
on your system. - Do the same (if required) with
<ILASM>
tag with path toilasm.exe
.