zoukankan      html  css  js  c++  java
  • 一堆DLL中找一个类

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Reflection;
    using System.Linq;

    namespace SampleConsole
    {
    class Program
    {
            static void Main(string[] args)
            {
                string find = "SessionState";
                string dir = @"D:\project\website\XXX\website\XXX.Core\trunk\Lib\Dll";
                new DirectoryInfo(dir)
                    .EnumerateFiles("*.dll"SearchOption.AllDirectories)
                    .AsParallel()
                    .Select(f => f.FullName)
                .Select(p =>
                {
                    try
                    {
                        return new
                        {
                            Path = p.ToLower().Replace(dir.ToLower(), string.Empty),
                            Assembly = Assembly.LoadFrom(p)
                        };
                    }
                    catch (BadImageFormatException) { return null; }
                }).Where(x => x != null)
                .Select(x =>
                    {
                        try
                        {
                            return new
                            {
                                Path = x.Path,
                                Types = x.Assembly.GetTypes().AsParallel()
                                        .Select(t => t.FullName)
                                        .Where(s => s.IndexOf(find) > -1)
                            };
                        }
                        catch (ReflectionTypeLoadException) { return null; }
                    }).Where(x => x != null && x.Types.Count() > 0)
                    .ToList()
                    .ForEach(x =>
                        Console.WriteLine(x.Path + "\n" + x.Types.Aggregate((a, b) => a + "\n" + b) + "\n\n")
                        );
            }
    }
    }
  • 相关阅读:
    Python 写入和读取Excel数据
    postman检查点详解
    禅道安装在不同系统下搭建步骤
    Linux下如何启动和关闭防火墙
    tomcat环境搭建
    Lniux下搭建LNMP环境
    Linux下搭建LAMP环境
    通过XAMPP导入WordPress网站建立个人博客
    在Windows下XAMPP的安装及使用教程
    linux 下安装配置xampp环境
  • 原文地址:https://www.cnblogs.com/goodspeed/p/1787079.html
Copyright © 2011-2022 走看看