深入探究动态语言运行时(DLR)的后期绑定与缓存机制
1. 后期绑定基础
在动态语言运行时(DLR)中,后期绑定是一项核心特性。下面是一个简单的示例代码,展示了如何使用 ConstantBinder 进行后期绑定:
private static void RunConstantBinderExample()
{
CallSiteBinder binder = new ConstantBinder();
CallSite<Func<CallSite, object, object, int>> site =
CallSite<Func<CallSite, object, object, int>>.Create(binder);
//This will invoke the binder to do the binding.
int result = site.Target(site, 5, 6);
Console.WriteLine("Result is {0}", result);
}
这里的 CallSite<T> 中的泛型类型 T 有特殊要求:
- 它必须是委托类型。
- 委托的第一个参数类型必须是 CallSite 。
在上述示例中, T 是 Func<
超级会员免费看
订阅专栏 解锁全文
56

被折叠的 条评论
为什么被折叠?



