- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试根据其他一些帖子解决问题。我正在查看列表中具有相同属性的多个对象,我需要验证它们在每个对象中的值是否相同。如果不是,我需要标记对象具有冲突的属性值。我正在尝试并且虽然可行的代码在下面,但始终返回 true 以将属性添加到列表中,即使列表项中的值都相同也是如此。
public List<string> JobHasConflictingTaxForms(Job job, List<string> propertiesToCheck)
{
var conflictingPropertiesList = new List<string>();
foreach(string prop in propertiesToCheck)
{
if (!job.TaxForms.TrueForAll(t => t.ARecord.GetType().GetProperty(prop)
.GetValue(t.ARecord, null) ==
job.TaxForms[0].ARecord.GetType().GetProperty(prop)
.GetValue(job.TaxForms[0].ARecord, null)))
{
conflictingPropertiesList.Add(prop);
}
}
return conflictingPropertiesList;
}
每个税单都有一个对象作为属性,称为“ARecord”。这些是我需要验证的属性对于每个税表都是普遍相同的,如果不是,那么我需要标记其中一个是不同的。我错过了什么,或者这个 lambda 语句做错了什么?即使我具有所有相同的值,或者具有相同值的三种形式,以及一种具有不同属性的形式,它也会返回相同的结果。它总是返回 true。
附言我也尝试过使用 Any(i => logic != other item)。但是没有按照我的预期工作。
TaxForm 类
public class TaxForm
{
#region Properties
public string TaxFormType
{
get;
set;
}
public string FileName
{
get;
set;
}
public string FileFullName
{
get;
set;
}
public bool ShouldProcess
{
get;
set;
}
public bool Corrected
{
get;
set;
}
public TRecord TRecord
{
get;
set;
}
public ARecord ARecord
{
get;
set;
}
public BRecord BRecord
{
get;
set;
}
public List<string> BRecords
{
get;
set;
}
public bool HasConflictingrecords
{
get;
set;
}
public bool HasDataConflict
{
get;
set;
}
#endregion
现在是 ARecord 类
public class ARecord
{
#region Properties
/// <summary>
/// Found at POS(12) for 8
/// </summary>
public string PayerTIN
{
get;
set;
}
/// <summary>
/// Found at POS(38) for 39.
/// </summary>
public string PayerName
{
get;
set;
}
/// <summary>
/// Found at POS(134) for 39.
/// </summary>
public string PayerAddress
{
get;
set;
}
/// <summary>
/// found at POS(255) for 14.
/// </summary>
public string PayerPhone
{
get;
set;
}
/// <summary>
/// Found at POS(2) for 3.
/// </summary>
public string PayerYear
{
get;
set;
}
#endregion
}
最佳答案
PropertyInfo.GetValue
方法返回它引用的属性的值作为 Object
类型。执行的 == 运算符是针对 Object
类的,而不是针对 String
的。
要执行正确的比较方法,您需要将调用 PropertyInfo.GetValue
的返回值转换为 string
,然后使用 == 运算符或调用静态 string.Equals
方法。
关于c# - Lambda 用于查找属性的差异,反射在 C# 中未正确返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25510739/
可以使用 lambda 和函数创建有序对(Lisp 中的缺点),如 Use of lambda for cons/car/cdr definition in SICP 所示。 它也适用于 Python
我正在尝试从另一个调用一个 AWS lambda 并执行 lambda 链接。这样做的理由是 AWS 不提供来自同一个 S3 存储桶的多个触发器。 我创建了一个带有 s3 触发器的 lambda。第一
根据以下源代码,常规 lambda 似乎可以与扩展 lambda 互换。 fun main(args: Array) { val numbers = listOf(1, 2, 3) f
A Tutorial Introduction to the Lambda Calculus 本文介绍乘法函数 The multiplication of two numbers x and y ca
我想弄清楚如何为下面的表达式绘制语法树。首先,这究竟是如何表现的?看样子是以1和2为参数,如果n是 0,它只会返回 m . 另外,有人可以指出解析树的开始,还是一个例子?我一直找不到一个。 最佳答案
在 C++0x 中,我想知道 lambda 函数的类型是什么。具体来说: #include type1 foo(int x){ return [x](int y)->int{return x * y
我在其中一个职位发布中看到了这个问题,它询问什么是 lambda 函数以及它与高阶函数的关系。我已经知道如何使用 lambda 函数,但不太自信地解释它,所以我做了一点谷歌搜索,发现了这个:What
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
Evaluate (((lambda(x y) (lambda (x) (* x y))) 5 6) 10) in Scheme. 我不知道实际上该怎么做! ((lambda (x y) (+ x x
我正在处理 MyCustomType 的实例集合如下: fun runAll(vararg commands: MyCustomType){ commands.forEach { it.myM
Brian 在他对问题 "Are side effects a good thing?" 的论证中的前提很有趣: computers are von-Neumann machines that are
在 Common Lisp 中,如果我希望两个函数共享状态,我将按如下方式执行 let over lambda: (let ((state 1)) (defun inc-state () (in
Evaluate (((lambda(x y) (lambda (x) (* x y))) 5 6) 10) in Scheme. 我不知道实际上该怎么做! ((lambda (x y) (+ x x
作为lambda calculus wiki说: There are several possible ways to define the natural numbers in lambda cal
我有一个数据类,我需要初始化一些 List .我需要获取 JsonArray 的值(我使用的是 Gson)。 我做了这个函数: private fun arrayToList(data: JsonAr
((lambda () )) 的方案中是否有简写 例如,代替 ((lambda () (define x 1) (display x))) 我希望能够做类似的事情 (empty-lam
我在 Java library 中有以下方法: public void setColumnComparator(final int columnIndex, final Comparator colu
我正在研究一个函数来计算国际象棋游戏中棋子的有效移动。 white-pawn-move 函数有效。当我试图将其概括为任一玩家的棋子 (pawn-move) 时,我遇到了非法函数调用。我已经在 repl
考虑这段代码(在 GCC 和 MSVC 上编译): int main() { auto foo = [](auto p){ typedef decltype(p) p_t;
我正在阅读一个在 lambda 内部使用 lambda 的片段,然后我想通过创建一个虚拟函数来测试它,该函数从文件中读取然后返回最大和最小数字。 这是我想出来的 dummy = lambda path
我是一名优秀的程序员,十分优秀!