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

首頁 > 編程 > .NET > 正文

Attribute/特性心得隨筆

2024-07-10 12:44:26
字體:
來源:轉載
供稿:網友
代碼如下:
<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>");
}
}
}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 武清区| 罗源县| 迭部县| 搜索| 读书| 玉山县| 塘沽区| 合肥市| 许昌县| 鲁甸县| 松江区| 西青区| 祁连县| 孝感市| 邛崃市| 清镇市| 乐平市| 比如县| 天全县| 依安县| 静安区| 赣州市| 蚌埠市| 九龙坡区| 万宁市| 吴旗县| 镇坪县| 广东省| 德钦县| 肇州县| 神木县| 华蓥市| 子洲县| 鹤山市| 通城县| 固镇县| 临清市| 绥阳县| 杂多县| 嘉黎县| 万源市|