GetProperties和Property Order [英] GetProperties and Property Order

查看:106
本文介绍了GetProperties和Property Order的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个简单的问题,但是我没有(在完整的

一堆谷歌搜索之后)能够找到答案:


对PropertyInfo的订单有什么保证
通过调用Type.GetProperties()返回的
对象?

来解释:


我正在编写实用程序包,它依赖于能够按照声明的顺序处理类型的属性(即在
source-order)。

在我的所有测试中(跨.NET Framework的v1.1和v2.0),
$通过调用Type.GetProperties()*返回的b $ b列表确实*包含源顺序中的

属性,但我无法确认是否

这将永远是这样。


提前感谢您的帮助,

Bevan。


I have a simple question, but one to which I haven''t (after a whole
bunch of Googling) been able to find an answer:

Are there any guarantees to the order of PropertyInfo
objects returned by a call to Type.GetProperties() ?
To explain:

I am writing utility package that is reliant on being able to process
the Properties of a type in the order they were declared (ie in
source-order).

In all my testing (across both v1.1 and v2.0 of the .NET Framework), the
list returned by a call to Type.GetProperties() *does* contain the
properties in source-order, but I haven''t been able to confirm whether
this will always be the case.

Thanks in advance for your help,
Bevan.

推荐答案

这是一个很酷/疯狂的问题!


我没有给你一个答案但是我想指出,如果存在语句顺序(属性或

无论如何)的情况,那么我不再认为它的OO编程了。

查看Pascal或Fortran!


(可以说我仍然会留在这个帖子中,因为

我也想知道答案!)

Thats a cool/crazy question!

I don''t have an answer for you but I want to point out that if a
situation existed where the order of statements (properties or
whatever) mattered, then I don''t think its OO programming anymore.
Check out Pascal or Fortran!

(Suffice to say I am still going to stay posted to this thread because
I want to know the answer too!)


Bevan Arps< be ******** @ rbnz.govt.nz>写道:
Bevan Arps <be********@rbnz.govt.nz> wrote:
我有一个简单的问题,但是我没有(在一整套谷歌搜索之后)能够找到答案:

对Type.GetProperties()调用返回的PropertyInfo
对象的顺序是否有任何保证?


编号特别是,我认为在1.1中所有成员返回的

Type.GetXXX *每次都以相同的顺序返回。在2.0中,我认为至少有一些这些电话是故意改变的,因为
改为以随机顺序返回会员,甚至可能是
在同一过程中不同的电话之间有所不同!

解释:

我正在编写的实用程序包依赖于能够处理的属性按照它们被声明的顺序输入(即在
源顺序中)。

在我的所有测试中(跨.NET Framework的v1.1和v2.0),<通过调用Type.GetProperties()*返回的列表确实*包含源顺序中的
属性,但我无法确认
是否总会如此。
I have a simple question, but one to which I haven''t (after a whole
bunch of Googling) been able to find an answer:

Are there any guarantees to the order of PropertyInfo
objects returned by a call to Type.GetProperties() ?
No. In particular, I believe that in 1.1 all members returned by
Type.GetXXX *were* returned in the same order each time. In 2.0, I
believe that at least some of these calls have been deliberately
changed to return the members in a random order, possibly even
different between different calls in the same process!
To explain:

I am writing utility package that is reliant on being able to process
the Properties of a type in the order they were declared (ie in
source-order).

In all my testing (across both v1.1 and v2.0 of the .NET Framework), the
list returned by a call to Type.GetProperties() *does* contain the
properties in source-order, but I haven''t been able to confirm whether
this will always be the case.




不要依赖它。


(对于部分课程,顺便说一下,*是*没有源订单 -

源文件可以按不同的顺序处理。)


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet 博客: http://www.msmvps.com/jon.skeet

如果回复小组,请不要给我发邮件



Don''t rely on it.

(With partial classes, by the way, there *is* no "source-order" - the
source files can be processed in different orders.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too





" Bevan Arps" <是******** @ rbnz.govt.nz>在留言中写道

新闻:uC ************** @ TK2MSFTNGP09.phx.gbl ...
Hi,

"Bevan Arps" <be********@rbnz.govt.nz> wrote in message
news:uC**************@TK2MSFTNGP09.phx.gbl...

我有一个简单的问题,但我没有(在一大堆谷歌搜索后)能够找到答案:

对于PropertyInfo的订单是否有任何保证
通过调用Type.GetProperties()返回的对象?


不是我知道是否,而且坦率地说我怀疑它是否会首先在OO设计中没有与b $ b相关,也就是它可能依赖于编译器和框架本身的b $ b。

要解释:

我正在编写依赖于它的实用程序包能够按照声明的顺序处理类型的属性(即按源顺序)。


为什么这很重要?

在我的所有测试中(跨.NET Framework的v1.1和v2.0),
通过调用Type.GetProperties()*返回的列表确实*包含源顺序中的
属性,但我无法确认是否总是如此。

I have a simple question, but one to which I haven''t (after a whole bunch
of Googling) been able to find an answer:

Are there any guarantees to the order of PropertyInfo
objects returned by a call to Type.GetProperties() ?
Not that I know if, and frankly I doubt it would be, first of all it''s not
relevant in an OO design , also it may be dependand of both the compiler and
of the framework itself.

To explain:

I am writing utility package that is reliant on being able to process the
Properties of a type in the order they were declared (ie in source-order).
Why is this important?
In all my testing (across both v1.1 and v2.0 of the .NET Framework), the
list returned by a call to Type.GetProperties() *does* contain the
properties in source-order, but I haven''t been able to confirm whether
this will always be the case.




最有可能导致编译器在读取时创建类型,并且框架的反射功能会发生这种情况。但是我不打赌它会花上



-

Ignacio Machin,

ignacio.machin AT dot.state.fl.us

佛罗里达州交通局



Most probably cause the compiler create the type as it reads it, and the
asme thing happens with the framework'' reflection feature. but I won''t bet
on it.

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


这篇关于GetProperties和Property Order的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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