错误绑定到目标方法 [英] Error binding to target method
本文介绍了错误绑定到目标方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
MethodInfo method = typeof(T).GetMethod("Parse", new[] { typeof(string) });
parse = Delegate.CreateDelegate(typeof(Func<T,string>), method);
T是在这种情况下,一个浮子。但是我得到一个错误的结合到目标的方法。解析我相信是一个静态方法。我已经看了看其他的例子,但我想不通为什么它不具有约束力。
T is a float in this case. However I am getting a Error binding to target method. Parse I believe is a static method. I have looked at other examples, but I can not figure out why it is not binding.
推荐答案
您交换 T
和字符串
因为该方法返回一个 T
不是字符串
。
you have to swap T
and string
because the method returns a T
not a string
.
我换成 T
与浮动
并按照code工作对我来说:
I replaced T
with float
and following code works for me:
MethodInfo method = typeof(float).GetMethod("Parse", BindingFlags.Static | BindingFlags.Public, null, new[] { typeof(string) }, null);
var parse = Delegate.CreateDelegate(typeof(Func<string, float>), method);
来源:VS智能感知和MSDN Func键(中T,TResult)代表一>
source: VS intellisense and MSDN Func(Of T, TResult) Delegate
这篇关于错误绑定到目标方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文