扩展方法在C#中的任何限制 [英] Extension method have any limitation in c#

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

问题描述

我要问,不添加扩展方法,数据类型的作品以同样的方式为微软的方法或没有任何可以limitaion。



这是有关经验的程序员谁了,而使用他们找一些限制。


解决方案

什么样的限制是怎么想的?我并不特别喜欢他们发现的方式 - 以及特别的方式,如果扩展类型后获得具有相同签名的方法,将静默与周围的扩展方法根本没有警告称为<。 / p>

有一些方法,使他们不工作,以及人们所喜欢的 - 例如,的你不能写一个委托类型和呼叫扩展方法它直接在lambda表达式或匿名方法 - 但这是不够合理的。



除此之外,我不知道有显著的局限性 - 我当然避风港T在哪里见过微软的源代码已经有大约扩展方法适用的特殊规则的任何情况。



您最后一句话使得它听起来像你的有无的看到了一些限制 - ?你能与我们分享


I want to ask, does adding extension methods to datatypes works in the same way as Microsoft's methods or do they have any limitaion.

This is relevant to experienced programmers who had find some limitations while using them.

解决方案

What sort of limitations are you thinking of? I'm not particularly fond of the way they're discovered - and in particular, the way that if the extended type later gains a method with the same signature, that will silently be called with no warnings around the extension method at all.

There are some ways in which they don't work as well as one might like - for example, you can't write an extension method for a delegate type and call it directly on a lambda expression or anonymous method - but that's reasonable enough.

Beyond that, I'm not aware of significant limitations - and I certainly haven't seen any situations where Microsoft code has had special rules applied around extension methods.

Your last sentence makes it sound like you have seen some limitations - could you share them with us?

这篇关于扩展方法在C#中的任何限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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