I have a class with a generic method:
public record OperationCollectionGeneric<OPERATIONTYPE> where OPERATIONTYPE: notnull, Enum { public OPERATIONTYPE Group { get; } public OperationCollectionGeneric(string part1, string? part2 = null, string? part3 = null) { Group = Enum.Parse<OPERATIONTYPE>(part1, true); } The Enum.Parse() method has the following error:
Error CS0453 The type 'OPERATIONTYPE' must be a non-nullable value type in order to use it as parameter 'TEnum' in the generic type or method 'Enum.Parse(ReadOnlySpan, bool)'
How can I pass the make sure that OPERATIONTYPE parameter is of type Enum
I tried to use the where keywork to set the enum type for the OPERATIONTYPE but it does not work.
where OPERATIONTYPE: struct, Enum. The constraint you have lets someone doOperationCollectionGeneric<Enum>, where you literally pass theEnumtypestructdefines a value type.