首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Matrix<T>.Build.Dense()创建Matrix<T>.Build.Dense()

使用Matrix<T>.Build.Dense()创建Matrix<T>.Build.Dense()
EN

Stack Overflow用户
提问于 2017-06-21 15:07:54
回答 1查看 449关注 0票数 1

我想返回一个创建密集Expression.Call矩阵的MathNet。

这就是我想要的矩阵:

代码语言:javascript
复制
Matrix<ContentType>.Build.Dense(Rows,Columns)

ContentType将是intdoubleComplex

但是我想使用Expression.Call创建它。以下是我的当前代码:

代码语言:javascript
复制
Expression.Call(
            typeof(Matrix<>)
                .MakeGenericType(ContentType)
                .GetProperty("Build")
                .GetMethod("Dense", new[] {typeof(int), typeof(int)}),
            Expression.Constant(Rows), Expression.Constant(Columns));

但是,这会导致生成错误:

代码语言:javascript
复制
[CS1955] Non-invocable member 'PropertyInfo.GetMethod' cannot be used like a method.

我做错了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-21 15:50:30

GetMethod类型上有PropertyInfo属性,它返回属性getter方法。您正在尝试将此属性用作方法(调用它)--从而导致编译器错误。相反,你应该这样做:

代码语言:javascript
复制
// 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));
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44679870

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档