最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Attribute/特性心得隨筆

 更新時間:2013年11月05日 16:19:45   作者:  
從事asp.net工作的相關(guān)人員對Attribute并不陌生吧,本文就來為大家介紹下Attribute特性,下面有個不錯的示例,喜歡的朋友感受下
復(fù)制代碼 代碼如下:

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

復(fù)制代碼 代碼如下:

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;
}
}

/*

*類

*/
復(fù)制代碼 代碼如下:

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; }
}
}

/*

*獲取

*/
復(fù)制代碼 代碼如下:

//獲取特性
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>");
}
}
}

相關(guān)文章

最新評論

漳平市| 沈阳市| 永新县| 鞍山市| 花垣县| 和政县| 鹤峰县| 田林县| 阜新| 南通市| 柘城县| 电白县| 日喀则市| 石家庄市| 宿迁市| 固阳县| 赞皇县| 扎兰屯市| 西乌珠穆沁旗| 芒康县| 永胜县| 浏阳市| 高邮市| 饶河县| 积石山| 老河口市| 延寿县| 家居| 盐池县| 东莞市| 清丰县| 凉城县| 醴陵市| 离岛区| 大英县| 高雄县| 通州市| 通江县| 岳西县| 出国| 临海市|