将在C#4支持扩展方法动态关键字? [英] Will the dynamic keyword in C#4 support extension methods?

查看:216
本文介绍了将在C#4支持扩展方法动态关键字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是<一个href=\"http://channel9.msdn.com/shows/Going+Deep/Inside-C-40-dynamic-type-optional-parameters-more-COM-friendly/\">listening一讲关于 C#4 动态关键词,我想知道......请问这个功能是正交的其他.NET功能,例如将它支持扩展方法?

I'm listening to a talk about C#4's dynamic keyword and I'm wondering... Will this feature be orthogonal to other .NET features, for example will it support extension methods?

public static class StrExtension {
    public static string twice(this string str) { return str + str; }
}
...
dynamic x = "Yo";
x.twice(); // will this work?


注意:被问到这个问题C#4被运前,这就是为什么它在未来的措辞紧张


Note: This question was asked before C#4 was shipped which is why it's phrased in the future tense.

推荐答案

从<一个href=\"http://$c$c.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=csharpfuture&DownloadId=3550\">\"New在C#4的Word文档特点:

动态查找将不能够
  找到扩展方法。是否
  扩展方法适用与否取决于
  关于该呼叫的静态上下文
  (即其使用条款发生),和
  此上下文信息是不
  目前保存为有效载荷的一部分。

Dynamic lookup will not be able to find extension methods. Whether extension methods apply or not depends on the static context of the call (i.e. which using clauses occur), and this context information is not currently kept as part of the payload.

这篇关于将在C#4支持扩展方法动态关键字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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