通用应用程序中的DataAnnotation

时间:2014-05-28 05:20:40

标签: win-universal-app

我在我的项目中使用了数据注释,但在通用应用程序中,它显示了没有DataAnnotations命名空间的错误。

Unversal App是否支持“使用System.ComponentModel.DataAnnotations”?

2 个答案:

答案 0 :(得分:1)

看起来不像。 According to their roadmap您必须向下滚动到底部表格才能看到它可用于除手机之外的所有平台。 :(

答案 1 :(得分:0)

是的,它是Windows Universal app中的支持,示例代码:

using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection;

namespace SystematixIndia.Universal.Extensions
{
    /// <summary>
    /// Provides extensions for the <see cref="Enum" /> class.
    /// </summary>
    public static class EnumExtensions
    {
        /// <summary>
        /// Gets the display name attribute as a string
        /// </summary>
        /// <param name="en">The enum.</param>
        /// <returns>The display name attribute as a string</returns>
        public static string ToDisplayNameAttribute(this Enum en)
        {
            return en.GetType().GetMember(en.ToString()).First().GetCustomAttribute<DisplayAttribute>().GetName();
        }
    }
}
相关问题