惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
CERT Recently Published Vulnerability Notes
D
Docker
GbyAI
GbyAI
博客园 - 三生石上(FineUI控件)
博客园_首页
H
Help Net Security
T
The Exploit Database - CXSecurity.com
Microsoft Security Blog
Microsoft Security Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
P
Privacy & Cybersecurity Law Blog
AWS News Blog
AWS News Blog
Spread Privacy
Spread Privacy
F
Full Disclosure
Blog — PlanetScale
Blog — PlanetScale
Y
Y Combinator Blog
V
Vulnerabilities – Threatpost
P
Proofpoint News Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
aimingoo的专栏
aimingoo的专栏
Simon Willison's Weblog
Simon Willison's Weblog
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
S
Security Affairs
T
Tailwind CSS Blog
T
Tor Project blog
W
WeLiveSecurity
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
The Hacker News
The Hacker News
腾讯CDC
M
MIT News - Artificial intelligence
D
DataBreaches.Net
量子位
Martin Fowler
Martin Fowler
T
Threat Research - Cisco Blogs
博客园 - 【当耐特】
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
云风的 BLOG
云风的 BLOG
C
Cisco Blogs
I
InfoQ
Engineering at Meta
Engineering at Meta
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
CXSECURITY Database RSS Feed - CXSecurity.com
O
OpenAI News
美团技术团队
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
L
LangChain Blog
A
About on SuperTechFans

博客园 - skylai

mvc3 小技巧 WCF学习之旅(一)---Hello World. WCF Client configuration Jquery表单验证 Jquery的一些常用信息 二进制、SOAP的序列化及反序列化 泛型之泛型约束 C#泛型之泛型委托 C#2.0泛型介绍之简单泛型类。 序列化之XML序列化(一) Vs2005的win form动态生成菜单 强制字符换行CSS版和C#版 js操作xml 读写XML文件 js的一些杂谈 一个button同时执行多个有返回值的函数的解决方法(return false; or return true;) DataGrid里应用radio单选按钮 限制字符输入(ASCII 码) 前两天刚看书看到的,来这里跟大家分享一下有关C#处理指令的问题
简单的Attribute实现.
skylai · 2007-07-29 · via 博客园 - skylai

C# Attribute class

    [AttributeUsage(AttributeTargets.Method)]
    
public class FastyouAttribute:Attribute
    
{
        
private string _name = string.Empty;
    
        
public FastyouAttribute(string name)
        
{
            _name 
= name; 
        }


        
public string Name
        
{
            
get return _name; }
            
set { _name = value; }
        }

    }

应用这个类

    public class AttributeClass
    
{
        [Fastyou(
"what's your name")]
        
public void getName()
        
{
            
//string name = "name";
        }

    }

访问结果

        public void AttributeFastyou()
        
{
            Type type 
= typeof(AttributeClass);
            
foreach (MethodInfo mothod in type.GetMethods())
            
{
                
foreach (Attribute at in mothod.GetCustomAttributes(true))
                
{
                    FastyouAttribute att 
= at as FastyouAttribute;
                    
if (att != null)
                    
{
                        
string sss = att.Name;//"what's your name"
                        string ddd = mothod.Name;//getName
                    }

                }


            }

        }


posted @ 2007-07-29 22:52  skylai  阅读(384)  评论(0)    收藏  举报

刷新页面返回顶部