欢迎来到代码驿站!

.NET代码

当前位置:首页 > 软件编程 > .NET代码

在Framework 4.0中:找出新增的方法与新增的类(一)

时间:2021-05-19 09:40:50|栏目:.NET代码|点击:
程序思路:动态加载V4和V2的mscorlib.dll程序集,通过反射进行比较。
之所以加载mscorlib.dll 是因为framework中的大部分类都在这里,而发生变更的也就是这里最多。

第一步:新建控制台程序:

加载程序集:

image

加载程序集完成后,自然要获取程序集中的所有Type,这里直接使用默认的GetTypes方法。

image

获取了v4Types v2Types之后,就要对v2Types里面的所有Typev4Types里面的所有Type进行比较,

而比较的内容就是GetMembers返回的所有MemberInfo.

完整代码如下:

复制代码 代码如下:

static void Main(string[] args)
{
    string v4AssemblyPath = @"C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll";
    string v2AssemblyPath = @"C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll";
    //Assembly v4Assembly = typeof(object).Assembly;
    Assembly v4Assembly = Assembly.LoadFile(v4AssemblyPath);
    Assembly v2Assembly = Assembly.LoadFile(v2AssemblyPath);
    Type[] v4Types = v4Assembly.GetTypes();
    Type[] v2Types = v2Assembly.GetTypes();
    foreach (Type v2Type in v2Types)
    {
        Type v4Type = v4Types.First(t => t.FullName == v2Type.FullName);
        MemberInfo[] v2Mis = v2Type.GetMethods();
        MemberInfo[] v4Mis = v4Type.GetMethods();
        if (v2Mis.Length != v4Mis.Length)
        {
            foreach (MemberInfo v2Mi in v2Mis)
            {
                bool isExist = false;
                foreach (MemberInfo v4Mi in v4Mis)
                {
                    if (v2Mi.Name == v4Mi.Name)
                    {
                        isExist = true;
                        break;
                    }
                }
                if (!isExist)
                {
                    Console.WriteLine("{0}:{1}", v2Type.FullName, v2Mi.Name);
                }
            }
        }
    }
    Console.WriteLine("程序执行完毕!");
    Console.ReadLine();
}


程序运行结果如下:

image

上一篇:C#调用Nero SDK刻录光盘的方法

栏    目:.NET代码

下一篇:windows系统下,如何在C#程序中自动安装字体

本文标题:在Framework 4.0中:找出新增的方法与新增的类(一)

本文地址:http://www.codeinn.net/misctech/124463.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有