I've trying to work with a struct (for the first time) and have come up with a slight issue I don't know how to work around.
public struct TextSelect<TEnum> where TEnum : Enum
{
public TextSelect(string input = "")
{
Input = input;
Values = EnumDto.ToList<TEnum>();
}
public string Input { get; set; }
public IEnumerable<EnumDto> Values { get; }
}
public TextSelect<IndustryType> Industry = new TextSelect<IndustryType>();
The problem relates to parameterless constructors.
I would like to initialize the Values
property when the struct is instantiated, but TEnum
is a type, not an instance value, so it doesn't count as a parameter.
As such, I get an compiler warning if the constructor has no parameters.
If I add an optional value, 'Input', I can trick the compiler and warning disappears, but the constructor still doesn't fire (presumably because it's empty).
Other than change it to a class, are there any other workarounds?
All advice appreciated.