主页 > 知识库 > Attribute/特性心得随笔

Attribute/特性心得随笔

热门标签:百度AI接口 网站排名优化 人工智能 客户服务 科大讯飞语音识别系统 电商新玩法 电销业务 国美全国运营中心
复制代码 代码如下:

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

标签:枣庄 攀枝花 拉萨 南平 厦门 咸宁 POS机 益阳

巨人网络通讯声明:本文标题《Attribute/特性心得随笔》,本文关键词  ;如发现本文内容存在版权问题,烦请提供相关信息告之我们,我们将及时沟通与处理。本站内容系统采集于网络,涉及言论、版权与本站无关。
  • 相关文章
  • 收缩
    • 微信客服
    • 微信二维码
    • 电话咨询

    • 400-1100-266