[英]Reflection Method Invoke - Failed to convert parameters
我有一個具有簽名的靜態方法:
pubic static foo (float,float,IEnumberable<IEnumberable<double>>)
我正在使用反射調用帶有以下參數的方法
int, int, and List<List<double>>,
這失敗了,在我看來, List<List<double>>
參數無法轉換。 我正在使用下面的代碼嘗試轉換參數
這可能嗎? 反射的局限性? 我以為List實現了IEnumerable接口並且可以正常工作。
var args = inputportvals.Select(x=>
{
if (x.First is IronPython.Runtime.List || x.First is IDynamicMetaObjectProvider)
{
return x.First;
}
if (x.First is IEnumerable || x.First is IList)
{
return x.First as IEnumerable;
}
else
{
return Convert.ChangeType(x.First, infos.Where(y=>y.Name == x.Second).First().ParameterType);
}
}
).ToArray();
funcdef.MethodPointer.Invoke(null,args);
List<List<double>>
不能轉換為IEnumerable<IEnumberable<double>>
:
List<List<double>> x = null;
IEnumerable<IEnumerable<double>> y = x; //does not compile and fails with an explicit cast
您需要自己執行轉換。 例如:
x.Cast<IEnumerable<double>>()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.