我想这对流利的接口。见,例如这个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?
发布评论