通过dll反射获得dll中有的逻辑类

2015-03-14 21:49:19  访问(2082) 赞(0) 踩(0)


        /// <summary>
        /// 
        /// </summary>
        /// <param name="fileName"></param>
        protected void LoadClassName(string fileName)
        {
            if (fileName == null || fileName.Trim().Length == 0)
                return;

            try
            {
                string curClassName = comboBox_ClassName.Text.Trim();

                Assembly ass = Assembly.LoadFile(fileName);

                Type[] tArray = ass.GetTypes();

                Type typeofUserControl  = typeof(UserControl);

                comboBox_ClassName.Items.Clear();

                comboBox_ClassName.Items.Add("-");

                bool isFind = false;
                Type curType = null;
                foreach (Type t in tArray)
                {
                    if (t == null)
                        continue;

                    isFind = false;
                    curType = t;

                    while (true)
                    {
                        if (curType == null)
                            break;

                        if (curType == typeofUserControl)
                        {
                            isFind = true;
                            break;
                        }

                        curType = curType.BaseType;
                    }

                    if (isFind)
                    {
                        comboBox_ClassName.Items.Add(t.FullName);
                    }
                }

                comboBox_ClassName.Text = curClassName;
            }
            catch 
            { 
            }
        }


上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)
 
  ┈全部┈  
 
(显示默认分类)