0

What I'm trying to code:

public class Condition<TEnum>
{
    public string Operator { get; set; }

    public bool Validate()
    {
        return Enum.TryParse<TEnum>(this.Operator, true, out _);
    }
}

Using the above code, I got this compilation error with Enum.TryParse method:

Error CS0453 The type 'TEnum' must be a non-nullable value type in order to use it as parameter 'TEnum' in the generic type or method 'Enum.TryParse(string, bool, out TEnum)'

I'm wondering How to implement generic enum validation properly?

Mhd
  • 2,778
  • 5
  • 22
  • 59

0 Answers0