我有一個枚舉定義如下:C#枚舉解析與思考
public enum Format {
Normal = 1,
Type2 = 2,
Type3 = 3
}
我試圖使用反射和調用動態類型轉換功能。但是,在下面的代碼中,「value」的值是「3」而不是「Type3」,並且它不被識別爲枚舉。是否可以使用int值,3來識別枚舉?
Type enumType = property.PropertyType;
if (Enum.IsDefined(enumType, value))
return Enum.Parse(enumType, value);
什麼_exactly_是'value'?它來自什麼? – SLaks
該值來自數據庫。該值是一個Db字符串值。 – Garrett