Background
Having a delphi background I am used to fixing lots of thgings using constants and const arrays et all. Also Delphi allpws to have type conversions on enums using helper classes. Now take a look at these enums from C#
public enum DateInterval { Off, Day, Month, Year };
public enum TimeInterval { Off, MilliSecond, Second, Minute, Hour };
public enum DateTimeInterval { Off, MilliSecond, Second, Minute, Hour, Day, Month, Year };
As you can see, there can be a logical conversion between thse enums, and I have managed to accomplish this using:
public static class DateIntervalHelper
{
public static DateTimeInterval ToDateTimeInterval(this TimeInterval aInterval)
{
switch (aInterval)
{
case TimeInterval.MilliSecond:
return DateTimeInterval.MilliSecond;
case TimeInterval.Second:
return DateTimeInterval.Second;
case TimeInterval.Hour:
return DateTimeInterval.Hour;
default: // ivOff
return DateTimeInterval.Off;
}
}
public static DateTimeInterval ToDateTimeInterval(this DateInterval aInterval)
{
switch (aInterval)
{
case DateInterval.Day:
return DateTimeInterval.Day;
case DateInterval.Month:
return DateTimeInterval.Month;
case DateInterval.Year:
return DateTimeInterval.Year;
default: // ivOff
return DateTimeInterval.Off;
}
}
}
In delphi I would rather do something like this
const
cDate2DateTimeInterval:array[DateInterval] of DateTimeInterval=(
DateTimeInterval.Off,
DateTimeInterval.Day,
DateTimeInterval.Month,
DateTimeInterval.Year);
cTime2DateTimeInterval:array[TimeInterval] of DateTimeInterval=(
DateTimeInterval.Off,
DateTimeInterval.MilliSecond,
DateTimeInterval.Second,
DateTimeInterval.Minute,
DateTimeInterval.Hour);
And then use these arrays to "map" the conversion. (Maybe some Snytax™ errors, but you will get the point)
Question
Wat would be a cleaner way to implement this conversion in C#, using Core3.1 ?