/// <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. 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;
}
} } // // get method informations from methodinfo [] array: // // /// Public String getmethodinfo (methodinfo [] myarraymethodinfo) {< br> string methodstr = ""; // getinformation for all methods. for (INT I = 0; I {< br> methodinfo mymethodinfo = (methodinfo) myarraymethodinfo [I]; methodstr + = "method" + I + ":" + mymethodinfo. name + environment. newline; }< br> 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;
}
Author's blog:Http://blog.csdn.net/davidullua/ |