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

推荐订阅源

Engineering at Meta
Engineering at Meta
博客园_首页
H
Help Net Security
WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
罗磊的独立博客
博客园 - 三生石上(FineUI控件)
B
Blog
I
InfoQ
SecWiki News
SecWiki News
T
Tailwind CSS Blog
Spread Privacy
Spread Privacy
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Vulnerabilities – Threatpost
N
Netflix TechBlog - Medium
P
Palo Alto Networks Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Vercel News
Vercel News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
K
Kaspersky official blog
M
MIT News - Artificial intelligence
S
Schneier on Security
T
Threat Research - Cisco Blogs
F
Fortinet All Blogs
Cyberwarzone
Cyberwarzone
Scott Helme
Scott Helme
aimingoo的专栏
aimingoo的专栏
Martin Fowler
Martin Fowler
MyScale Blog
MyScale Blog
The Cloudflare Blog
Recent Announcements
Recent Announcements
Security Latest
Security Latest
G
GRAHAM CLULEY
IT之家
IT之家
Y
Y Combinator Blog
The Last Watchdog
The Last Watchdog
腾讯CDC
Google DeepMind News
Google DeepMind News
V
V2EX
S
Securelist
TaoSecurity Blog
TaoSecurity Blog
B
Blog RSS Feed
S
SegmentFault 最新的问题
博客园 - 叶小钗
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
Project Zero
Project Zero
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
F
Full Disclosure

博客园 - xpoint

Sybase 11.0.3 bcp数据报错! Sybase SQL Server 11.0.x 调优方案...(未完成) Windows Server Family 上安装Office 2000 你在使用Gmail,Wallop,MSN Spaces,Three Degrees吗? 网易的邮箱太慢了,还要别的选择吗? 学了学awk,也算是收获 Microsoft PowerToys for Windows XP 给Windows,SCO,AIX添加静态路由 给博客园的bloger提供若干GMail邀请。(暂放半天,明天移帖) 微软的应用程序块列表 了解POP3协议,使用简单的代码监控pop3邮箱,或者不用代码,直接使用telnet 微软为什么把标准提升的这么快, .Net Framework 1.1-> 2.0,连核心的类库都换了! 让你的gVim支持Miscrosoft Visual C++ 2003 设置一个Label控件上文字的字体样式和字体大小随机的代码 得到本机socket选项的全部默认值。 Linux TCP/IP 协议栈源码分析(一) 国外高手参加世界编程大赛时的参赛作品(转载) UltraEdit-32中的小bug。 还是关于《设计模式》
反射的任务
xpoint · 2004-07-31 · via 博客园 - xpoint

// Programming C# by O'Reilly & Associates,Inc
// 
//
//----------------------------------------------------------------------------------- 
// 反射常用于以下四个任务
//  (1) 浏览元数据           
//  (2) 查询类型 :利用反射查看配件的类型,方法,性质,事件,以及和改类型相关的一切信息
//  (3) 与方法和性质迟绑定 (动态调用)
//  (4) 在运行时创建类型   (反射发送)
//-----------------------------------------------------------------------------------
using System;
using System.Reflection;
using System.Collections;
namespace Programing_CSharp_Reflection

    
//测试类
    public class App
    
{
        
public static void Main(string[] args)
        
{
            MyMath mm 
= new MyMath();
            
int result = mm.Function_Sum(10,15);
            Console.WriteLine(
"Result is {0}",result);
            Console.WriteLine();
            
// (1)浏览元数据
            System.Reflection.MemberInfo mbrInfo = typeof(MyMath);
            
object[] attributes = mbrInfo.GetCustomAttributes(typeof(BugFixAttribute),false);
            
foreach(object attribute in attributes)
            
{
                BugFixAttribute bfa 
= (BugFixAttribute) attribute;
                Console.WriteLine(
" BugID  :{0}",bfa.BugID);
                Console.WriteLine(
"Progammer:{0}",bfa.Programmer);
                Console.WriteLine(
"Date     :{0}",bfa.Date);
                Console.WriteLine(
"Comment  :{0}",bfa.Comment);
            }

            
// (2)查询类型
            Assembly asb = Assembly.Load("Mscorlib.dll");
            Type[] types 
= asb.GetTypes();
            
foreach(Type t in types)
            
{
                Console.WriteLine(
"Type is  {0}",t);
                MemberInfo[] mbrInfoArray 
= t.GetMembers();
                
//也可以查询一个类型的成员,甚至可以查找特定的成员,例如只查找"Get"打头的方法
                
// MemberInfo[] mbrInfoArray = t.FindMembers(MemberTypes.Method,BindingFlags.Default,Type.FilterName,"Get*")
                foreach(MemberInfo mbr in mbrInfoArray)
                
{
                    Console.WriteLine(
"{0} IS A {1}",mbr,mbr.MemberType);
                }

                
            }

            Console.WriteLine(types.Length);
            Console.ReadLine();
        }

    }

   
// 自定义的属性类
   public class BugFixAttribute : System.Attribute
   
{
       
private int bugID;
       
private string programmer;
       
private string date;
       
private string comment;
       
public int BugID {get{return bugID;}set{bugID=value;}}
       
public string Programmer {get{return programmer;}set{programmer=value;}}
       
public string Date {get{return date;}set{date=value;}}
       
public string Comment {get{return comment;} set{comment=value;}} 
       
//构造函数
       public BugFixAttribute(int bugID,string programmer,string date)
       
{
           
this.bugID = bugID;
           
this.programmer = programmer;
           
this.date = date;
       }

   }

   
//将属性应用到一个类上
   [BugFixAttribute(100,"zh-bin@163.com","2004/07/31",Comment="添加加法运算")]
   
public class MyMath
   
{
       
public int Function_Sum(int i,int j)
       
{
           
return i+j;
       }

       
public int Function_Sub(int i,int j)
       
{
           
return i-j;
       }

   }

}