Lorsque j'exécute le code suivant, j'obtiens RuntimeBinderException: 'object' does not contain a definition for 'SetIt'
.Echec dynamique de la classe interne privée
public interface IInput { }
public interface IThing<in TInput>
{
void SetIt(TInput value);
}
public class ThingMaker
{
private class Thing<TInput> : IThing<TInput>
where TInput : IInput
{
public void SetIt(TInput value){}
}
private class Input : IInput {}
public IThing<IInput> GetThing()
{
return new Thing<IInput>();
}
public IInput GetInput()
{
return new Input();
}
}
class Program
{
static void Main(string[] args)
{
var thingMaker = new ThingMaker();
var input = thingMaker.GetInput();
dynamic thing= thingMaker.GetThing();
thing.SetIt(input);
}
}
Si je passe thing
à un var
il fonctionne très bien. Donc, clairement, thing
a SetIt
. Comment ça se passe quand j'utilise dynamique? Est-ce que tout ce qui fonctionne comme var
ne devrait pas fonctionner quand c'est dynamic
?
Je pense que cela a quelque chose à voir avec Thing<TInput>
étant une classe interne privée parce qu'elle fonctionne quand je la rends publique.