我想返回一个创建密集Expression.Call矩阵的MathNet。
这就是我想要的矩阵:
Matrix<ContentType>.Build.Dense(Rows,Columns)ContentType将是int,double或Complex。
但是我想使用Expression.Call创建它。以下是我的当前代码:
Expression.Call(
typeof(Matrix<>)
.MakeGenericType(ContentType)
.GetProperty("Build")
.GetMethod("Dense", new[] {typeof(int), typeof(int)}),
Expression.Constant(Rows), Expression.Constant(Columns));但是,这会导致生成错误:
[CS1955] Non-invocable member 'PropertyInfo.GetMethod' cannot be used like a method.我做错了什么?
发布于 2017-06-21 15:50:30
在GetMethod类型上有PropertyInfo属性,它返回属性getter方法。您正在尝试将此属性用作方法(调用它)--从而导致编译器错误。相反,你应该这样做:
// first get Build static field (it's not a property by the way)
var buildProp = typeof(Matrix<>).MakeGenericType(ContentType)
.GetField("Build", BindingFlags.Public | BindingFlags.Static);
// then get Dense method reference
var dense = typeof(MatrixBuilder<>).MakeGenericType(ContentType)
.GetMethod("Dense", new[] { typeof(int), typeof(int) });
// now construct expression call
var call = Expression.Call(
Expression.Field(null /* because static */, buildProp),
dense,
Expression.Constant(Rows),
Expression.Constant(Columns));https://stackoverflow.com/questions/44679870
复制相似问题