国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

Attribute/特性心得隨筆

2024-07-10 13:15:04
字體:
來源:轉載
供稿:網友

復制代碼 代碼如下:


<p>/*</p><p>*特性</p><p>*/</p>


復制代碼 代碼如下:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// DisAttribute 的摘要說明
/// </summary>
public class DisAttribute : Attribute
{
private string _message;
/// <summary>
/// 描述
/// </summary>
public string Message
{
get { return _message; }
}

public DisAttribute(string message)
{
this._message = message;
}
}


/*

*類

*/

復制代碼 代碼如下:


using System;
using System.Collections.Generic;
using System.EnterpriseServices;
using System.Linq;
using System.Web;
using System.Web.DynamicData;


/// <summary>
/// User 的摘要說明
/// </summary>
[DisAttribute("User"),TableName("user"),Description("user")]
public class User
{
private int? _id;
/// <summary>
/// Id
/// </summary>
[DisAttribute("主鍵")]
public int? Id
{
get { return _id; }
set { _id = value; }
}


private string _name;
/// <summary>
/// 名稱
/// </summary>
[DisAttribute("名稱")]
public string Name
{
get { return _name; }
set { _name = value; }
}
}


/*

*獲取

*/

復制代碼 代碼如下:


//獲取特性
User u = new User();
Type _t = u.GetType();
foreach (Attribute a in _t.GetCustomAttributes(true))
{
if (a.GetType().ToString() == "DisAttribute")
{
DisAttribute _da = (DisAttribute)a;
if (_da != null)
{
Response.Write(_da.Message + "<br>");
}
}
}
//獲取所有屬性
u.Id = 888888;
u.Name = "陳奕迅";
foreach (PropertyInfo item in _t.GetProperties())
{
//特性
Attribute atr = item.GetCustomAttribute(typeof(DisAttribute));
if (atr.GetType().ToString() == "DisAttribute")
{
DisAttribute _da = (DisAttribute)atr;
if (_da != null)
{
Response.Write(_da.Message + "<br>");
}
}
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 彰武县| 建始县| 新泰市| 玉山县| 庄河市| 寿光市| 彝良县| 若尔盖县| 柘城县| 蓬莱市| 高安市| 蒲城县| 泊头市| 浮梁县| 靖宇县| 教育| 翼城县| 德庆县| 平谷区| 汕尾市| 南投县| 珲春市| 河北区| 绩溪县| 施秉县| 根河市| 扶余县| 浮梁县| 大石桥市| 宕昌县| 乐山市| 祥云县| 余干县| 高碑店市| 湘西| 闻喜县| 武平县| 平和县| 高密市| 五原县| 观塘区|