会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
Ray Lynn's Blog. - - - - - - - - - 林伟!!!
首页
新随笔
联系
订阅
管理
定制特性学习笔记
我的定制特性学习笔记
using
System;
using
System.Collections.Generic;
using
System.Text;
using
System.Reflection;
using
System.Diagnostics;
namespace
AttrTestControl
{
[MyAttr(
"
构造中
"
,Desc
=
"
属性
"
)]
public
class
Program
{
static
void
Main(
string
[] args)
{
Assembly a
=
Assembly.LoadFrom(Process.GetCurrentProcess().ProcessName
+
"
.exe
"
);
Type type
=
typeof
(Program);
foreach
(Attribute attr
in
type.GetCustomAttributes(
true
))
{
MyAttrAttribute newAttr
=
attr
as
MyAttrAttribute;
if
(newAttr
!=
null
)
Console.WriteLine(newAttr.Desc);
}
Console.ReadLine();
}
}
[AttributeUsage(AttributeTargets.All, AllowMultiple
=
true
, Inherited
=
true
)]
class
MyAttrAttribute : Attribute
{
private
string
_Desc;
/**/
///
<summary>
///
Desc
///
</summary>
public
string
Desc
{
get
{
return
_Desc;
}
set
{
_Desc
=
value;
}
}
public
MyAttrAttribute(
string
sDesc)
{
_Desc
=
sDesc;
}
}
}
发表于
2007-06-29 15:57
Ray Lynn
阅读(
296
) 评论(
1
)
收藏
举报
刷新页面
返回顶部
公告