我们在C#3.0中有扩展属性吗? [英] Do we have extention properties in C# 3.0?

查看:61
本文介绍了我们在C#3.0中有扩展属性吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




C#3.0扩展方法对我们很有用。我们对扩展属性有类似的

概念吗?


谢谢,

Max

解决方案

2008年7月23日星期三15:42:19 -0700,Max2006< al ******* @ newsgroup.nospam>

写道:


C#3.0扩展方法对我们有用。我们对扩展属性有类似的

概念吗?



不,我不这么认为。但有趣的想法。也许他们正在考虑

吧。


Max2006写道:


C#3.0扩展方法对我们很有用。我们对扩展属性有类似的

概念吗?



No.


并且存在语法问题。


与方法的区别在于它们没有参数列表。


被扩展的对象作为额外参数传递。


语法如何区分

a方法,没有参数和属性?


Arne


2008年7月23日星期三17:11:48 -0700,Arne Vajh ?? j< ar ** @ vajhoej.dkwrote:


[...]

语法应如何区分没有参数的

a方法和属性?



扩展属性的语法:


public int MyProperty(this SomeClass arg0)

{

get;

set;

}


只是因为现在申报的房产不在不包括参数列表,

并不意味着他们不能。我相信

声明块中有足够的其他信息来区分属性和方法。


毫无疑问还有其他有效的方法可以允许声明一个

扩展属性,但上面看起来最简单,并且

与我一致。


Pete


Hi,

C# 3.0 extension methods become useful for us. Do we have the similar
concept for extension properties?

Thank you,
Max

解决方案

On Wed, 23 Jul 2008 15:42:19 -0700, Max2006 <al*******@newsgroup.nospam>
wrote:

C# 3.0 extension methods become useful for us. Do we have the similar
concept for extension properties?

No, I don''t think so. But interesting idea. Maybe they''re thinking about
it.


Max2006 wrote:

C# 3.0 extension methods become useful for us. Do we have the similar
concept for extension properties?

No.

And there is a syntax problem.

Properties are distinguished from methods by the fact that they
do not have an argument list.

The object being extended is passed as an extra argument.

How should the syntax be to distinguish between
a method with no arguments and a property ?

Arne


On Wed, 23 Jul 2008 17:11:48 -0700, Arne Vajh??j <ar**@vajhoej.dkwrote:

[...]
How should the syntax be to distinguish between
a method with no arguments and a property ?

Syntax for an extension property:

public int MyProperty(this SomeClass arg0)
{
get;
set;
}

Just because properties as declared now don''t include an argument list,
that doesn''t mean they couldn''t. There''s enough other information in the
declaration block to distinguish a property from a method, I believe.

No doubt there are other valid ways to allow the declaration of an
extension property, but the above seems most straightforward and
consistent to me.

Pete


这篇关于我们在C#3.0中有扩展属性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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