首页 > Windows开发 > 详细

Part 53 to 55 Talking about Reflection in C#

时间:2015-10-12 01:52:25      阅读:246      评论:0      收藏:0      [点我收藏+]

Part 53 Reflection in C#

技术分享

 

Part 54 Reflection Example

here is the code

技术分享
private 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());
        }
    }
}            
技术分享

Part 55 Late binding using reflection

技术分享

Part 53 to 55 Talking about Reflection in C#

原文:http://www.cnblogs.com/gester/p/4870568.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!