相关疑难解决方法(0)

在.NET 4.0中动态实现接口(C#)

借助.NET 4.0中的新动态功能,似乎应该可以动态实现接口,例如:

public interface IFoo 
{
    string Bar(int baz);
}

public class Foo : IFoo
{
    public string Bar(int baz) { return baz.ToString(); }
}

public class Proxy : IDynamicMetaObjectProvider
{
    private readonly object target;

    public Proxy(object target) { this.target = target; }

    // something clever goes here
}
Run Code Online (Sandbox Code Playgroud)

然后我希望有一些方法可以写:

dynamic proxy = new Proxy(new Foo());
IFoo fooProxy = (IFoo)proxy; // because the target object implements it
string bar = fooProxy.Bar(123); // delegates through to the target implementation
Run Code Online (Sandbox Code Playgroud)

但是,到目前为止,我还不确定要替换什么// …

.net c# dynamic .net-4.0 c#-4.0

46
推荐指数
3
解决办法
3万
查看次数

标签 统计

.net ×1

.net-4.0 ×1

c# ×1

c#-4.0 ×1

dynamic ×1