HTMLAgilityPack表达式不能包含lambda表达式 [英] HTMLAgilityPack Expression cannot contain lambda expressions

查看:191
本文介绍了HTMLAgilityPack表达式不能包含lambda表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想股利的InnerText称为album_notes。正如我在其他许多地方一样,我的代码如下:

I want the InnerText of the div called album_notes. As I did in many other places, my code is the following:

public void Album_Notes(HtmlAgilityPack.HtmlDocument bandHTML)
{
        this.lblNotes.Text = bandHTML.DocumentNode.Descendants("div").First(x => x.Id == "album_notes").InnerHtml;

的TextBlock,lblNotes,没有文字的结果结束。如果我打开快速监视,同时在调试模式下,我得到以下结果:

The TextBlock, lblNotes, ends up with no text as the result. If I open the QuickWatch while in debug mode, I get the following result:

表达式不能包含lambda表达式

Expression cannot contain lambda expressions

尽管我已经使用了完全相同的语法其他地方的至少10倍,在相同的应用程序。奇怪的是,它实际上并没有引发错误或任何东西,它只是填充为空字符串文本块。

even though I've used the exact same syntax at least 10 other times elsewhere in the same app. The odd thing is that it doesn't actually throw an error or anything, it just fills the TextBlock with an empty string.

这有什么错我的代码?

推荐答案

表达式不能包含lambda表达式消息没有来自HTMLAgilityPack但从快速监视功能。基本上,lambda表达式只是一个syntaxic糖:在编译时拉姆达转换为真实的功能。由于它的东西编译过程中发生的事情,你不能在运行时创建一个全新的lambda(即,在快速监视窗口)

The Expression cannot contain lambda expressions message doesn't come from the HTMLAgilityPack but from the QuickWatch feature. Basically, a lambda expression is just a syntaxic sugar: upon compilation the lambda is converted to a 'real' function. Since it's something happening during compilation, you can't create a brand new lambda at runtime (that is, in the QuickWatch window).

现在的问题是:为什么是 lblNotes.Text 空的?不幸的是,我不知道没有看到的HTML代码。不过,如果没有错误,这意味着album_notes分区已被发现(否则你将有一个空引用除外)。因此,的innerHTML 属性可能是空的。

Now the question is: why is lblNotes.Text empty? Unfortunately, I can't know without seeing the HTML code. Though, if there's no error, it means that the "album_notes" div has been found (otherwise you would have a null reference exception). Therefore, the InnerHtml property is probably empty.

您可以检查通过重写代码中的一位:

You can check that by rewriting your code a bit:

public void Album_Notes(HtmlAgilityPack.HtmlDocument bandHTML)
{
    var div = bandHTML.DocumentNode.Descendants("div").First(x => x.Id == "album_notes");
    this.lblNotes.Text = div.InnerHtml;
}



这样,如果你把一个断点就上线,您可以检查 DIV div.InnerHtml 在快速监视窗口中。

This way, if you put a breakpoint on the last line, you can check the value of div and div.InnerHtml in the quickwatch window.

这篇关于HTMLAgilityPack表达式不能包含lambda表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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