应扩展属性被添加到C#4.0? [英] Should extension properties be added to C# 4.0?

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

问题描述

我想这对流利的接口。见,例如这个Channel9上的讨论。可能会需要还增加了索引属性。

I've wanted this for fluent interfaces. See, for example this Channel9 discussion. Would probably require also adding indexed properties.

你有什么想法?会利多于语言混乱?

What are your thoughts? Would the advantages outweigh the "language clutter"?

推荐答案

在我的书的#1最实质性的原因扩展属性的实现流畅周围无主代码的接口模式。我围绕NHibernate会话的包装,使之更加intitutive用,所以我可以做类似

In my book the #1 most substantial reason for extension properties is implementing fluent interface patterns around unowned code. I built a wrapper around the NHibernate session to make it more intitutive to work with so I can do logic similar to

public bool IsInTransaction
{
    get { return _session.Is().Not.Null && _session.Is().InTransaction; }
}



这看起来很愚蠢的是必须有一个方法是没有办法对我来说,插入是作为一个属性,除非我直接修改会话对象的来源。

Which looks very stupid that Is must be a method as there is no way for me to insert the Is as a property unless I directly modify the source on the session object.

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

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