I have the following method:
public static IEnumerable<SelectListItem> GetSpacedOptions<T>() where T : struct
{
var t = typeof(T);
if (!t.IsEnum)
{
throw new ArgumentException("Not an enum type");
}
var options = Enum.GetValues(t).Cast<T>()
.Select(x => new SelectListItem
{
Value = ((int) Enum.ToObject(t, x)).ToString(),
Text = Regex.Replace(x.ToString(), "([A-Z])", " $1").Trim()
});
return options;
}
What I need to do is to add a boolean parameter called zeroPad. So that if it is not supplied the method will be unchanged but if supplied then the Text output will be always a two digit string such as “01”, “04” or “77”.
How can I add that parameter. There seems no place to add it.
How about providing the default value as
false.-User can call it in both ways –
If value is not specified,
zeroPadvalue will befalseby default