I have a string typeString
which I'm trying to parse to an Enum with 30 cases, all of which have rather unique return statements. In some books I have seen a control flow like this used
if (!Enum.TryParse(typeString, true, out replicatingInstrumentType))
{
Log.Error("Unknown Replicating instrument type: " + typeString);
return new EmptyInstrument(instrumentIdentifier, Currency.EUR);
}
switch (replicatingInstrumentType)
{
case TypeA:
{
return TypeAReturnStatement;
}
// .....
// more cases here ....
// .....
case TypeZ:
{
return TypeZReturnStatement;
}
default:
{
return new EmptyInstrument(instrumentIdentifier, Currency.EUR);
}
}
whereas I've always figured one should do
if (Enum.TryParse(typeString, true, out replicatingInstrumentType))
{
switch (replicatingInstrumentType)
{
case TypeA:
{
return TypeAReturnStatement;
}
// .....
// more cases here ....
// .....
case TypeZ:
{
return TypeZReturnStatement;
}
default:
{
return new EmptyInstrument(instrumentIdentifier, Currency.EUR);
}
}
}
Log.Error("Unknown Replicating instrument type: " + typeString);
return new EmptyInstrument(instrumentIdentifier, Currency.EUR);
Besides the visual diference, is there any advantage/disadvantage over using one versus the other? Is there a consensus on which approach is better?