程序集中的类顺序 [英] Order of Classes within an Assembly

查看:23
本文介绍了程序集中的类顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是什么决定了程序集中类的顺序?

What determines the order of classes within an Assembly?

还有……有没有办法改变它?

And.. is there a way to change it?

附加信息:您可以通过自己的反射检查排序,也可以使用ILDASM之类的工具,禁用字母排序,然后您也将获得排序.

Additional info: you can check the ordering either through reflection yourself, or you can use a tool like ILDASM, disable the alphabetical sorting, and then you will also get the order.

顺序似乎以一种奇怪的方式由编译器决定.

Order seems to be in a strange way determined by the compiler.

我已经尝试了一些事情..比如重命名类(顺序保持不变),还编辑 .csproj 文件以更改 .cs 文件的顺序.

I already tried some things.. like renaming the classes (order stays the same), also editing the .csproj file to change the order of the .cs files.

我的主要关注点是 VS2008、C#、.net 3.5.

My main focus is VS2008, C#, .net 3.5.

更新:我确实有一个顺序很重要的场景(外部程序通过反射通过我的程序集) - 我需要在那里特殊订单.除此之外 - 你是完全正确的 - 顺序真的不重要.

Update: I do have a scenario where the order matters (external program going through my assembly through reflection) - and I need special order there. Apart from this - you are totally right - order really should not matter.

推荐答案

我想说这是一个实现细节,很可能由任何特定的编译器决定.

I'm going to stick my neck out here and say this is an implementation detail and may well be decided by any particular compiler.

由于这是一个实现细节,您不应该或不必担心.当然,如果这真的很重要(不明白为什么),您可以随时编写自己的 IL.

Since this is an implementation detail you shouldn't or needn't be concerned. Of course if this really is important (can't see why) you can always write your own IL.

我给你留下以下来自 埃里克的博客:

I leave you with the following quote from Eric's blog:

是否编译相同的 C# 程序两次保证产生相同的二进制输出?

Is compiling the same C# program twice guaranteed to produce the same binary output?

没有

这篇关于程序集中的类顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆