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 + = "" + 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 ("The 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;
}