我正在使用以下内容:
public static SelectList GetOptions<T>(string value = null) where T : struct
{
var values = EnumUtilities.GetSpacedOptions<T>();
var options = new SelectList(values, "Value", "Text", value);
return options;
}
public static IEnumerable<SelectListItem> GetSpacedOptions<T>(bool zeroPad = false) where T : struct
{
var t = typeof(T);
if (!t.IsEnum)
{
throw new ArgumentException("Not an enum type");
}
var numberFormat = zeroPad ? "D2" : "g";
var options = Enum.GetValues(t).Cast<T>()
.Select(x => new SelectListItem
{
Value = ((int) Enum.ToObject(t, x)).ToString(numberFormat),
Text = Regex.Replace(x.ToString(), "([A-Z])", " $1").Trim()
});
return options;
我的枚举具有值:
public enum DefaultStatus {
Release = 0,
Review = 1,
InProgress = 2,
Concept = 3,
None = 99
};
据我了解,数字格式应该给出我的值“01”、“02”等,但它给了我“1”、“2”、“3”..
有什么明显的我做错了吗?