如果这不是一个 Windows Phone 8 项目,如果我想显示人类可读的枚举版本,我会使用像这样的 niftt DataAnnotation
public enum InstallationType
{
[Display(Description="Forward of Bulk Head")]
FORWARD = 0,
[Display(Description="Rear of Bulk Head")]
REAR = 1,
[Display(Description="Roof Mounted")]
ROOF = 2,
}
并使用某种东西将它们拉出来,以达到以下效果:
public static string GetDescriptionFromEnumValue(Enum value)
{
DisplayAttribute attribute = value.GetType()
.GetField(value.ToString())
.GetCustomAttributes(typeof(DisplayAttribute), false)
.SingleOrDefault() as DisplayAttribute;
return attribute == null ? value.ToString() : attribute.Description;
}
简单, 但我的问题是 System.ComponentModel.DataAnnotation 在 Windows Phone 中不可用。我尝试过使用可移植类库,但是当我以 WP8 为目标时,我失去了访问该命名空间的能力。
还有哪些其他选择?
最佳答案
System.ComponentModel.DataAnnotation 在 Windows Phone 中不可用,您可以使用 Linq。 按照这个例子绑定(bind)枚举,
关于c# - Windows Phone 8 - 枚举和数据注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22957640/