c# - 将条件传递给 Tuple<string, string, Func<bool>> 的 Func<bool>

标签 c# properties tuples

我正在尝试创建一个元组列表,其中包含用于验证的属性和条件。所以我想到了这个想法:

List<Tuple<string, string, Func<bool>>> properties = new List<Tuple<string, 
                                                                    string,
                                                                    Func<bool>>> 
{
    Tuple.Create(FirstName, "User first name is required", ???),
};
...

如何将类型为 (FirstName == null) 的表达式作为 Func 传递?

最佳答案

像这样(使用 lambda expression ):

var properties = new List<Tuple<string, string, Func<bool>>> 
{
    Tuple.Create<string, string, Func<bool>>(
                 FirstName, 
                 "User first name is required",
                 () => FirstName == null),
};

关于c# - 将条件传递给 Tuple<string, string, Func<bool>> 的 Func<bool>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31004922/

相关文章:

c# - 在 MySQL 和 C# 中获取 "both"日期和时间的正确 DateTime 格式是什么

c# - 将 Stylecop 集成到 Jenkins 的 .NET 项目中

iphone - Objective-c 现代运行时在接口(interface) block 中同时使用属性和 ivars

ios5 - Objective-C 2.0 中属性 "Synthesize"和 "Dynamic"的澄清

java - 将输入添加到 TupleList

c# - 如何告诉 ASP.Net MVC 从 JSON 反序列化的所有传入日期都应该是 UTC?

C#编译器(csc.exe)内存溢出编译嵌套类型和Linq

UML 序列图调用属性

python - 从长度为 1 的元组中解压返回值

python - 仅将非空列表转换为列表列表中的元组