Anyone know a good workaround for the lack of an enum generic constraint?

后端 未结 12 1428
情书的邮戳
情书的邮戳 2020-11-22 15:37

What I want to do is something like this: I have enums with combined flagged values.

public static class EnumExtension
{
    public static bool IsSet

        
12条回答
  •  面向向阳花
    2020-11-22 16:03

    The way I do it is put a struct constraint, then check that T is an enum at runtime. This doesn't eliminate the problem completely, but it does reduce it somewhat

提交回复
热议问题