复制代码代码如下所示:
*****特性

复制代码代码如下所示:
使用系统;
使用system.collections.generic;
使用LINQ系统;
使用系统;

X
的disattribute / / /注
X
公共课disattribute:属性
{
_message字符串;
X
公共的描述
X
公共字符串消息
{
得到的回报_message {;}
}

公共disattribute(字符串)
{
这_message =消息;
}
}

*

*类

* /
复制代码代码如下所示:
使用系统;
使用system.collections.generic;
使用system.enterpriseservices;
使用LINQ系统;
使用系统;
使用system.web.dynamicdata;


X
用户说明
X
{ disattribute(用户),而(用户),描述(用户)}
用户类
{
私有_id;
X

X
{ disattribute(主要)}
public int ID
{
得到的回报_id {;}
集合{ _id =值;}
}


_name字符串;
X
只是名字
X
{ disattribute(名称)}
公共字符串名称
{
得到的回报_name {;}
集合{ _name =值;}
}
}

*

*获得

* /
复制代码代码如下所示:
获取/特性
用户u =新用户();
型_t = u.gettype();
foreach(属性在_t.getcustomattributes(真的))
{
如果(a.gettype)(ToString)(= =disattribute )
{
disattribute _da =(disattribute)一;
如果(_da!= null)
{
响应。写(_da.message + );
}
}
}
获取所有属性
美国编号= 888888;
陈奕迅;
foreach(PropertyInfo项目_t.getproperties())
{
特点
属性法item.getcustomattribute(typeof(disattribute));
如果(ATR .GetType)(ToString)(= =disattribute )
{
disattribute _da =(disattribute)ATR;
如果(_da!= null)
{
响应。写(_da.message + );
}
}
}