FEATURE REQUEST:通过ref参数设置属性 [英] FEATURE REQUEST: Property set via ref parameter

查看:107
本文介绍了FEATURE REQUEST:通过ref参数设置属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




通过允许使用属性设置这将是一个很好的自然方式

通过一个REF参数设置方法调用。


为什么这不被允许超出我的范围,是的我知道它们是

get_和set_方法的包装,但如果他们在那里给一个

FIELD的印象,那么他们应该拥有一个领域的所有功能,而不是一些半美元的实施。


谢谢。

Hi,

It would be nice and a natural way to use a property set by permitting it
to be set via a REF parameter on a method call.

Why this isnt being allowed is beyond me, yes I know they are wrappers for
get_ and set_ methods but if they are there to give the impression of a
FIELD, then they should have all the functionality of a field and not some
half brained implementation.

Thanks.

推荐答案

< di ******** @ discussion.microsoft.com>写道:
<di********@discussion.microsoft.com> wrote:
通过允许它通过方法调用上的REF参数设置,这将是一个很好的自然方式来使用属性集。


我恐怕不同意......

为什么这不被允许超出我的意思,是的我知道它们是包装纸
get_和set_方法,但是如果他们在那里给人一种
FIELD的印象,那么他们应该拥有一个字段的所有功能,而不是一些半脑的实现。
It would be nice and a natural way to use a property set by permitting it
to be set via a REF parameter on a method call.
I''m afraid I don''t agree...
Why this isnt being allowed is beyond me, yes I know they are wrappers for
get_ and set_ methods but if they are there to give the impression of a
FIELD, then they should have all the functionality of a field and not some
half brained implementation.




不,因为他们只是*不是*字段。通过

引用传递变量创建另一个具有相同内存槽的变量 -

只是属性不起作用。开发人员应该有一个清晰的视图

,属性实际上是伪装的方法而不是伪装的字段。


传递变量无论如何,通常应该避免引用,这是一个诚实的方法 - 这通常是一种试图做太多的方法的迹象。


-

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

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



No, because they''re simply *not* fields. Passing a variable by
reference creates another variable with the same memory slot - that
just isn''t how properties work. Developers should have a clear view
that properties are really methods in disguise rather than fields in
disguise.

Passing variables by reference should usually be avoided anyway, to be
honest - it''s usually a sign of a method trying to do too much.

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


他们给人的印象是字段,这就是为什么我们可以做一个

SomeObj.SomeProperty = someValue就像一个字段赋值,同样适用于获取

someVal = SomeObj.SomeProperty;再次就像一个FIELD。


他们可能被实现为方法,但这不是我们作为开发人员的问题

调用它们,这是一个较低的级别。


它们可以提供更多的字段扩展性和更好的方式来控制字段。


它们是包装器字段(概念上)和方法的包装器

(实现)。


是的,他们在那里给人一种印象。



" Jon Skeet [C#MVP]" < SK *** @ pobox.com>在消息中写道

新闻:MP ************************ @ msnews.microsoft.c om ...
They are giving the impression of fields, thats why we can do a
SomeObj.SomeProperty = someValue just like a field assignment, same for get
someVal = SomeObj.SomeProperty; again justlike a FIELD.

They maybe implemented as methods, but thats not our problem as a developer
calling them, thats a lower level.

They are there to give more extensibility to fields and a greater way to
control fields.

They are wrappers for fields (conceptually), and wrappers for methods
(implentation).

So Yes, they are there to give an impression of fields.


"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
< di ******** @ discussion.microsoft.com>写道:
<di********@discussion.microsoft.com> wrote:
这将是一个很好的自然方式来使用属性设置允许
它通过方法调用上的REF参数设置。
It would be nice and a natural way to use a property set by permitting it to be set via a REF parameter on a method call.



我害怕我不同意......



I''m afraid I don''t agree...

为什么这不被允许超出我,是的我知道它们是包装
for get_和set_方法,但如果他们在那里给人一种
FIELD的印象,那么他们应该拥有一个字段的所有功能,而不是
一半半脑的实现。
Why this isnt being allowed is beyond me, yes I know they are wrappers for get_ and set_ methods but if they are there to give the impression of a
FIELD, then they should have all the functionality of a field and not some half brained implementation.



不,因为他们只是*不是*领域。通过
引用传递一个变量会创建另一个具有相同内存槽的变量 - 这就不是属性的工作方式。开发人员应该有一个清晰的观点
属性实际上是伪装的方法,而不是伪装的字段。

通常应该避免通过引用传递变量,以便诚实 - 这通常是一种方法试图做太多的迹象。

-
Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet
如果回复该组,请不要给我发邮件



No, because they''re simply *not* fields. Passing a variable by
reference creates another variable with the same memory slot - that
just isn''t how properties work. Developers should have a clear view
that properties are really methods in disguise rather than fields in
disguise.

Passing variables by reference should usually be avoided anyway, to be
honest - it''s usually a sign of a method trying to do too much.

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



< di ******** @ discussion.microsoft.com>写道:
<di********@discussion.microsoft.com> wrote:
他们给出了字段的印象,这就是为什么我们可以做一个
SomeObj.SomeProperty = someValue就像一个字段赋值,相同的获取
someVal = SomeObj。 SomeProperty;再次就像一个FIELD。


是的,但这并不意味着他们应该(或者确实)在每个可能的方式中表现得像

中的字段。

它们可能被实现为方法,但这不是我们作为开发人员调用它们的问题,这是一个较低的级别。


不,不是,真的。它完全符合C#规范。属性*是*

只是伪装的方法,任何开发人员都没有掌握

,这会让人感到困惑。例如,你有没有听说过你可以指定的字段但没有使用的值?
?然而,

是只有setter但没有getter的属性。同样地,

直接赋值也不能抛出异常等。

它们可以为字段提供更多的可扩展性和更好的控制字段的方法。 br />
它们是字段的包装(概念上)和方法的包装器
(实现)。


不,它们是对象状态的包装器,不需要由字段表示的


是的,他们在那里给人一种印象。
They are giving the impression of fields, thats why we can do a
SomeObj.SomeProperty = someValue just like a field assignment, same for get
someVal = SomeObj.SomeProperty; again justlike a FIELD.
Yes, but that doesn''t mean they should (or do) behave like fields in
every possible way.
They maybe implemented as methods, but thats not our problem as a developer
calling them, thats a lower level.
No it''s not, really. It''s all in the C# specification. Properties *are*
just methods in disguise, and any developer who doesn''t get to grips
with that is going to get confused. For instance, have you ever heard
of a field you can assign to but not use the value of? And yet there
are properties which only have setters but no getters. Similarly,
straight assignment can''t throw exceptions etc.
They are there to give more extensibility to fields and a greater way to
control fields.

They are wrappers for fields (conceptually), and wrappers for methods
(implentation).
No, they are wrappers for the state of the object, which needn''t be
represented by fields.
So Yes, they are there to give an impression of fields.




他们在那里给出了字段的简单语法,但这并不意味着

它们应被视为字段。


-

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

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



They''re there to give the easy syntax of fields, but that doesn''t mean
they should be regarded as fields.

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


这篇关于FEATURE REQUEST:通过ref参数设置属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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