是否有一个.NET属性用于指定“显示名称"?财产? [英] Is there a .NET attribute for specifying the "display name" of a property?

查看:60
本文介绍了是否有一个.NET属性用于指定“显示名称"?财产?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在允许您为类中的属性指定用户友好名称的属性?

Is there a property that allows you to specify a user friendly name for a property in a class?

例如,说我有以下课程:

For example, say I have the following class:

public class Position
{
     public string EmployeeName { get; set; }
     public ContactInfo EmployeeContactInfo { get; set; }
}

我想指定EmployeeName属性的显示名称为"Employee Name",而EmployeeContactInfo属性的显示名称为"Employee Contact Information".

I'd like to specify that the display name for the EmployeeName property is "Employee Name" and the display name for the EmployeeContactInfo property is "Employee Contact Information".

编写我自己的属性类很容易,允许我执行此操作:

It's easy enough to write my own attribute class that allows me to do this:

[PropertyDisplayInfo(DisplayName = "Employee Name")]
public string EmployeeName { get; set; }

但是.NET中已经包含了类似的东西吗?

But is something like this already included in .NET?

推荐答案

是的,有 System.ComponentModel.DisplayNameAttribute

这篇关于是否有一个.NET属性用于指定“显示名称"?财产?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆