Wenn ich den folgenden Code ausführen, bekomme ich RuntimeBinderException: 'object' does not contain a definition for 'SetIt'
.Dynamische Fehler auf private innere Klasse
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);
}
}
Wenn ich thing
zu einem var
wechseln funktioniert es gut. Also klar, thing
hat SetIt
. Wie kommt das, wenn ich dynamisch benutze? Sollte keine Sache, die als var
funktioniert auch funktionieren, wenn es dynamic
ist?
Ich denke, es hat etwas mit Thing<TInput>
eine private innere Klasse zu tun, weil es funktioniert, wenn ich es öffentlich mache. Hier