【发布时间】:2014-03-14 18:24:33
【问题描述】:
假设你有这个:
Type theType = typeof(Foobar);
object thingy = new Foobar();
Func<Foobar,bool> FooWork = (f) => return true;
Delegate work = FooWork;
//Without using static cast operations, how do I use 'theType' variable to
//cast the 'work' Delegate back to something I can invoke?
//This next line is very wrong...
bool result = ((Func<theType, bool>)work)(thingy);
要重申评论,如何在不使用静态转换操作的情况下进行转换?我只是想让work 变量保存FooWork 委托,而不知道Foobar 类型。
我可以解决我的整体问题,如果我简单地让我的包装类通用,这样work 变量就变成了通用的,但目前我正试图避免这种情况。
【问题讨论】:
标签: c# reflection delegates