标题:在我实际工作中反射技术的应用(2)
取消只看楼主
ioriliao
Rank: 7Rank: 7Rank: 7
来 自:广东
等 级:贵宾
威 望:32
帖 子:2829
专家分:647
注 册:2006-11-30
结帖率:78.95%
 问题点数:0 回复次数:0 
在我实际工作中反射技术的应用(2)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using
using System.Reflection;
//这个例子的应用场景是这样的
//我知道一个属性,像POTitle属性,
//而且知道其位于E:\Program\FongIan\Server
//文件夹内是以ServerData作后缀的DLL文件
//现在我的目的就是为了找出这个属性
//具体属于哪个DLL.
namespace DLLofTabelName
{
    class Program
    {
        static void Main(string[] args)
        {
            var TableName ="";
            if (args.Length > 0)
            {      
                TableName = args[0];      
            }
            else
            {
                TableName = Console.ReadLine();
            }

            var FileName = Directory.GetFiles(@"E:\Program\FongIan\Server", "*ServerData.dll");

                for (var i = 0; i < FileName.Length; i++)
                {
                     
                        var myAssembly = Assembly.LoadFrom(FileName[i]);
                        
                        var myTypes = myAssembly.GetTypes();

                        foreach (var type in myTypes)
                        {
                            if (type.Name == TableName)
                            {

                                Console.WriteLine("{0}表所在的DLL文件是:{1}", TableName,type.Module);
                            }
                           
                        }
                  
                }

                Console.ReadLine();
            }                                    
    }
}
" border="0" />
搜索更多相关主题的帖子: 反射 
2008-08-22 11:53



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-229411-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.452788 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved