I have a FaultType
enum
with more than 100 members:
public enum FaultType
{
FaultType1,
FaultType2,
FaultType3,
FaultType4,
FaultType5,
}
And I have a FaultTypeConstants
class
corresponding to FaultType
:
public class FaultTypeConstants
{
public const int FaultType1 = 600;
public const int FaultType2 = 100;
public const int FaultType3 = 453;
public const int FaultType4 = 200;
public const int FaultType5 = 300;
}
Now, I want to populate the List<FaultType>
based on FaultTypeConstants
values:
public static List<FaultType> GetFaults(List<int> FaultConstants)
{
var faults = new List<FaultType>();
FaultConstants.ForEach(fc => {
switch (fc)
{
case FaultTypeConstants.FaultType1:
faults.Add(FaultType.FaultType1);
break;
case FaultTypeConstants.FaultType2:
faults.Add(FaultType.FaultType2);
break;
case FaultTypeConstants.FaultType3:
faults.Add(FaultType.FaultType3);
break;
case FaultTypeConstants.FaultType4:
faults.Add(FaultType.FaultType4);
break;
case FaultTypeConstants.FaultType5:
faults.Add(FaultType.FaultType5);
break;
default:
break;
}
});
return faults;
}
Is there a better way to do this?
int
s directly in theenum
, why not put it in aDictionary<FaultType,int>
? What possible reason could there be for splitting this into anenum
and aClass
? \$\endgroup\$