I have a switch case statement containing enum values as cases. These enum values are time units. Now I want to generate a timespan by using an enum value and a long value so like this:
2 (long) Minutes (Enum value)
1 (long) Year (Enum value)
... and so on.
This is the switch-case statement:
private const double yearValue = 365.2425;
public TimeSpan ResetTimeSpan
{
get
{
switch (ResetTimeUnitEnumValue)
{
case TimeUnit.Seconds:
return new TimeSpan(0,0,0, (int)ResetTime);
case TimeUnit.Minutes:
return new TimeSpan(0, 0, (int)ResetTime, 0);
case TimeUnit.Hours:
return new TimeSpan(0, (int)ResetTime, 0);
case TimeUnit.Days:
return new TimeSpan((int)ResetTime, 0, 0, 0);
case TimeUnit.Months:
return new TimeSpan((int)(ResetTime * (yearValue / 12)), 0, 0, 0);
case TimeUnit.Years:
return new TimeSpan((int)(ResetTime * yearValue), 0, 0, 0);
default:
throw new ArgumentOutOfRangeException();
}
}
}
But I don't like it and it feels very double. Could anyone review this and refactor it, since I'm not able to see it.