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

推荐订阅源

K
Kaspersky official blog
Engineering at Meta
Engineering at Meta
D
DataBreaches.Net
Stack Overflow Blog
Stack Overflow Blog
Microsoft Security Blog
Microsoft Security Blog
Y
Y Combinator Blog
B
Blog RSS Feed
GbyAI
GbyAI
P
Proofpoint News Feed
aimingoo的专栏
aimingoo的专栏
MyScale Blog
MyScale Blog
D
Docker
阮一峰的网络日志
阮一峰的网络日志
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recorded Future
Recorded Future
美团技术团队
The Register - Security
The Register - Security
V
Visual Studio Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Tailwind CSS Blog
爱范儿
爱范儿
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
The Blog of Author Tim Ferriss
博客园 - 司徒正美
量子位
B
Blog
F
Fortinet All Blogs
Martin Fowler
Martin Fowler
博客园 - 【当耐特】
MongoDB | Blog
MongoDB | Blog
A
About on SuperTechFans
I
InfoQ
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
有赞技术团队
有赞技术团队
雷峰网
雷峰网
大猫的无限游戏
大猫的无限游戏
J
Java Code Geeks
L
LangChain Blog
Latest news
Latest news
S
SegmentFault 最新的问题
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Blog — PlanetScale
Blog — PlanetScale
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Cisco Talos Blog
Cisco Talos Blog
F
Full Disclosure
C
Cisco Blogs
D
Darknet – Hacking Tools, Hacker News & Cyber Security
W
WeLiveSecurity
T
Tenable Blog
T
Tor Project blog

博客园 - xiaolei1982

asp.net的ajax的实现 spring:bean生命周期(转贴) 在myeclipse下整合spring和hibernate(转贴) Struts+Spring+Hibernate练习(转贴) spring:bean注入(转贴) - xiaolei1982 - 博客园 解析eclipse下生成Hibernate DAO中的几个方法(转贴) ASP.NET ViewState 实现分析(转贴) 自定义控件源码(转贴) ASP.NET服务器控件的开发(4)(转贴) ASP.NET服务器控件的开发(3)(转贴) ASP.NET服务器控件的开发(2) (转贴) ASP.NET服务器控件的开发(1)(转贴) Web 页本是无状态而断续的(转贴) asp.net控件开发基础(3)(转贴) asp.net控件开发基础(6)(转贴) asp.net控件开发基础(5)(转贴) asp.net控件开发基础(4)(转贴) asp.net控件开发基础(2)(转贴) asp.net控件开发基础(1)(转贴)
C#中使用反射显示程序集的所有类型和属性(转贴)
xiaolei1982 · 2008-04-14 · via 博客园 - xiaolei1982

Posted on 2008-04-14 22:21  xiaolei1982  阅读(251)  评论(0)    收藏  举报

/// <summary>
  
///
  
/// loads a *.dll file from txtMethods and invokes all methods int it.
  
/// lists all types in the assembly
  
///
  
/// </summary>
  
/// <param name="sender"></param>
  
/// <param name="e"></param>

  private void btnList_Click(object sender, System.EventArgs e)
  
{

   
string fileName=labelFile.Text.Trim();
   
string result="";
   txtMethods.Text
="";
   txtTypes.Text
="";

   
if(File.Exists(fileName))
   
{
    
try
    
{
     Assembly assembly
=Assembly.LoadFrom(fileName);
     Type[] types
=assembly.GetTypes();
     result
="The Assembly contains the following types :"+Environment.NewLine;
    
     
for(int i=0;i<types.GetLength(0);++i)
     
{
      result
+="\t "+i+":"+types[i].Name+" "+" "+Environment.NewLine;

      
// Get the public methods.
      MethodInfo[] myArrayMethodInfo=types[i].GetMethods(BindingFlags.Public|BindingFlags.Instance|BindingFlags.DeclaredOnly);
      txtMethods.Text
=txtMethods.Text+Environment.NewLine+"The number of public methods in "+types[i].Name+" is "+myArrayMethodInfo.Length+Environment.NewLine;
      
// get all the methods.
      txtMethods.Text=txtMethods.Text+getMethodInfo(myArrayMethodInfo);
      
/*
      // Get the nonpublic methods.
      MethodInfo[] myArrayMethodInfo1 = myType.GetMethods(BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.DeclaredOnly);
      Console.WriteLine("\nThe number of protected methods is {0}.", myArrayMethodInfo1.Length);
      // Display information for all methods.
      LabelFile.Text=DisplayMethodInfo(myArrayMethodInfo1);
      
*/


     }


     
foreach(Type myType in types)
     
{
      
// Get the public properties.
      PropertyInfo[] myPropertyInfo = myType.GetProperties(BindingFlags.Public|BindingFlags.Instance);
      Console.WriteLine(
"The mumber of public properties in "+myType.Name+" is {0}.", myPropertyInfo.Length);
      
// Display the public properties.
      getPropertyInfo(myPropertyInfo);
      
// Get the nonpublic properties.
      PropertyInfo[] myPropertyInfo1 = myType.GetProperties(BindingFlags.NonPublic|BindingFlags.Instance);
      txtMethods.Text
=txtMethods.Text+Environment.NewLine+("The number of NonPublic properties in "+myType.Name+" is "+ myPropertyInfo1.Length)+Environment.NewLine;
      
// Display all the nonpublic properties.
      txtMethods.Text=txtMethods.Text+getPropertyInfo(myPropertyInfo1);
     }


     txtTypes.Text
=result;
    }

    
catch(Exception ee)
    
{
     
throw ee;
    }

    
   }


  }


  
/// <summary>
  
/// get Method informations from MethodInfo[] Array:
  
/// </summary>
  
/// <param name="myArrayMethodInfo"></param>
  
/// <returns></returns>

  public string getMethodInfo(MethodInfo[] myArrayMethodInfo)
  
{
   
string methodStr="";
   
///
   
///getinformation for all methods.

   for(int i=0;i<myArrayMethodInfo.Length;i++)
   
{
    MethodInfo myMethodInfo 
= (MethodInfo)myArrayMethodInfo[i];
    methodStr
+="Method "+i+" :"+ myMethodInfo.Name+Environment.NewLine;
   }
   
   
return methodStr;
  }


  
/// <summary>
  
/// get properties information from PropertyInfo[] Array:
  
/// </summary>
  
/// <param name="myPropertyInfo"></param>
  
/// <returns></returns>

  public string getPropertyInfo(PropertyInfo[] myPropertyInfo)
  
{
   
string propStr="";
   
// Display information for all properties.
   for(int i=0;i<myPropertyInfo.Length;i++)
   
{
    PropertyInfo myPropInfo 
= (PropertyInfo)myPropertyInfo[i];
    propStr
+="property "+i+":"+ myPropInfo.Name+" type:"+ myPropInfo.PropertyType+Environment.NewLine;
   }

   
return propStr;
  }

刷新页面返回顶部