Il y a un comportement étrange avec l'utilisation dynamique C# 4.0:Quelque chose ne va pas avec le mot-clé dynamique dans C# 4.0?
using System;
class Program {
public void Baz() { Console.WriteLine("Baz1"); }
static void CallBaz(dynamic x) { x.Baz(); }
static void Main(string[] args) {
dynamic a = new Program();
dynamic b = new { Baz = new Action(() => Console.WriteLine("Baz2")) };
CallBaz(a); // ok
CallBaz(b); // ok
CallBaz(a); // Unhandled Exception:
// Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:
// The name 'Baz' is bound to a method and cannot be used like a property
}
}
J'utilise Visual Studio 2010 Release Candidate.
Est-ce un bug? Si c'est vrai, cela sera-t-il corrigé dans la version?
Où est Eric Lippert: D –
Je peux le reproduire aussi ... Le premier appel à CallBaz (a) fonctionne bien, le second appel échoue. Cela ressemble à un bug en effet, et un sérieux ... –
Intéressant.J'ai envoyé un e-mail dans une liste appropriée - j'espère que cela attirera bientôt l'attention. –