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")
                        );
            }
    }
    }
  • 相关阅读:
    POJ 1948 Triangular Pastures
    2018ACM/ICPC 青岛现场赛 E题 Plants vs. Zombies
    三大博弈
    ACM-ICPC 2018年北京网络赛 D-80 days
    hdu 2062 Subset sequence
    转-利用 Python 练习数据挖掘
    内联函数
    C++中冒号(:)和双冒号(::)的用法
    理性,感性和爱
    修改IE8搜索框为指定搜索引擎,如CSDN、百度知道等
  • 原文地址:https://www.cnblogs.com/goodspeed/p/1787079.html
Copyright © 2011-2022 走看看