Part 53 Reflection in C#
Part 55 Late binding using reflectionprivate void btnDiscover_Click(object sender, EventArgs e)
{
lbMethods.Items.Clear();
lbProperties.Items.Clear();
lbConstructor.Items.Clear();
string typeName = txtTypeName.Text.Trim();
Type t = Type.GetType(typeName);
if (t == null)
{
MessageBox.Show("Type Is No Exit, Please Enter A Right Type!", "Warnning", MessageBoxButtons.OK);
txtTypeName.Clear();
txtTypeName.Focus();
}
else
{
MethodInfo[] methods = t.GetMethods();
PropertyInfo[] properties = t.GetProperties();
ConstructorInfo[] constructors = t.GetConstructors();
foreach (var method in methods)
{
lbMethods.Items.Add(string.Concat(method.ReturnType.Name," ", method.Name));
}
foreach (var property in properties)
{
lbProperties.Items.Add(string.Concat(property.PropertyType.Name, " ", property.Name));
}
foreach (var constructor in constructors)
{
lbConstructor.Items.Add(constructor.ToString());
}
}
}