应扩展属性被添加到C#4.0?

编程入门 行业动态 更新时间:2024-10-27 17:24:00
本文介绍了应扩展属性被添加到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?

本文发布于:2023-11-12 00:46:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580030.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!