扩展方法在vsto项目中失败 [英] Extension methods fail in vsto projects

查看:69
本文介绍了扩展方法在vsto项目中失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的VSTO Excel项目中,我正在调用一种方法 在我引用的另一个项目的类中。此方法返回IEnumerable< MyClass>。当我尝试在调用此方法的结果上调用ToArray()时,我得到的是''object'
不包含'ToArray'的定义。我有"使用System.Linq"在我班上如果我从另一个非vsto项目调用此方法,它就像我期望的那样工作。似乎我设置为此方法
调用结果的变量发现自己绑定为动态变量。为什么会发生这种情况超出我的想法。

In my VSTO Excel project I'm calling a method  in a class from another project that I have referenced. This method returns an IEnumerable<MyClass>. When I try to call ToArray() on the results from calling this method all I get is "'object' does not contain a definition for 'ToArray'". I have "using System.Linq" in my class. If I call this method from another, non vsto project, it all works just as I would expect. It seems as if the variable that I set to the result of this method call finds itself bound as a dynamic variable. Why this happens though is beyond me.

任何想法?

推荐答案

还有更多。我在无法在IEnumerable< MyClass>上调用ToArray的类中添加了以下方法:结果:

There is more. I added the following method to the class that fail to call ToArray on the IEnumerable<MyClass> result:

private IEnumerable<MyClass> GetMatches(int value, DateTime from, DateTime to)
{
yield break;
}

如果我从同一个类调用此方法并尝试调用ToArray()结果我得到的是:

If I call this method from the same class and try to call ToArray() on the result all I get is this:

'Sportnik.Excel.Stff。< GetMatches> d__11'
不包含定义
for 'ToArray'

'Sportnik.Excel.Stff.<GetMatches>d__11' does not contain a definition for'ToArray'


这篇关于扩展方法在vsto项目中失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆