无法将表达式类型字符串转换为bool [英] Cannot convert expression type string to bool

查看:132
本文介绍了无法将表达式类型字符串转换为bool的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

((source  as  Segment).Parent.AllSegments.GetSegments(  2200D  STC  .Any(x => x.GetFieldValue( null  String  .Empty, 3 )。等于(  U)) 







嗨这可能很简单问题,但我不知道如何解决它,



基本上我试图实现的是((来源为Segment).Parent.AllSegments.GetSegments (2200D,STC)将在返回的字段上返回几个字段Iam检查是否有任何字段等于U.做某事......



GetFieldValue是一个扩展方法,返回类型是字符串,任何返回类型都是bool ..抛出不能Con vert表达式字符串到bool



请给我一些建议如何解决它。



我尝试了什么:



我用谷歌搜索但找不到合适的解决方案。

解决方案

几种可能性:

1)查看你的GetFieldValue方法 - 你用三个参数调用它:null,一个字符串和一个整数。检查它所期望的参数并确保它们有效。然后看看它对它们的确切作用。

2)同样适用于你的GetSegments方法:你传递两个字符串 - 所以看看方法里面发生了什么。

错误不是编译错误 - 这是一个例外。这意味着它与你在其中一个方法中使用的数据字段中的值有关。

我首先查看每个方法并查看调试器中发生的确切内容。

((source as Segment).Parent.AllSegments.GetSegments("2200D","STC").Any(x=>x.GetFieldValue(null,String.Empty, 3).Equals("U")))




Hi this could be simple question but I'm unaware how to resolve it,

basically wt I am trying to achieve is ((source as Segment).Parent.AllSegments.GetSegments("2200D","STC") will return me few fields on the returned fields Iam Checking if Any field that has equal to U. do something....

GetFieldValue is an extension method return type is string, and any return type is bool..its throwing as Cannot Convert expression type string to bool

please give me some suggestions how to resolve it.

What I have tried:

I googled but couldn't find any suitable solution.

解决方案

Couple of possibilities:
1) Look at your GetFieldValue method - you are calling it with three parameters: null, a string, and an integer. Check the parameters it expects and make sure they are valid. Then look at exactly what it does with them.
2) Same applies to your GetSegments method: you pass two strings - so look at what happens to them inside the method as well.
The error isn't a compilation error - it's an exception. Which means that it's something to do with the values in the data fields you use inside one of the methods.
I'd start by breakpointing each of them and looking at exactly what is happening in the debugger.


这篇关于无法将表达式类型字符串转换为bool的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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