1

I have used Data Annotations in my project, but in the universal app, it shows an error for there is no namespace for DataAnnotations.

Is "using System.ComponentModel.DataAnnotations" supported in Unversal App ?

4

2 回答 2

1

看起来不像。 根据他们的路线图, 您必须向下滚动到底部表格才能看到它适用于除手机以外的所有平台。:(

于 2014-05-29T21:55:48.030 回答
0

是的,它在 Windows 通用应用程序中得到支持,示例代码:

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();
        }
    }
}
于 2016-10-28T07:43:31.063 回答