C# 特性
using System.ComponentModel.DataAnnotations;
//特性是个类,继承自Attribute
//系统自带特性
//自定义特性
class AccountViewModel
{
[Required]
[Display(Name ="邮箱")]
[Define("这是第一个特性的创建!")]
public string Email { get; set; }
}
/// <summary>
/// 创建特性
/// </summary>
public class DefineAttribute:Attribute
{
public DefineAttribute(string showInfo)
{
Console.WriteLine(showInfo);
}
}
本文来自博客园,作者:.net&new,转载请注明原文链接:https://www.cnblogs.com/wugh8726254/p/17413510.html
浙公网安备 33010602011771号