I have a number of lists that I want to store as statics, so they are explicitly named.
Gender
, MaritalStatus
and ResidentalStatus
are all enum types.
static readonly Lazy<IEnumerable<EnumDto>> _gender = GetLazyOptions<Gender>();
static readonly Lazy<IEnumerable<EnumDto>> _maritalStatus = GetLazyOptions<MaritalStatus>();
static readonly Lazy<IEnumerable<EnumDto>> _residentalStatus = GetLazyOptions<ResidentialStatus>();
I need to be able to access the appropriate field using the generic method - something like the ones below:
public static IEnumerable<EnumDto> GetOption1<TEnum>() where TEnum : Enum
{
}
public static IEnumerable<EnumDto> GetOptions2<TEnum>(this TEnum @enum) where TEnum : Enum
{
}
The idea is then to then use a switch
statement to find the right field (from the Enum type), but as yet I haven't been able to get it to work for me syntactically:
switch(typeof(@enum))
{
case Gender: return _gender;
}
I've already checked out this thread, but with no success:
Any advice appreciated.