Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 从给定列表中选择包含给定值的动态C#表达式_.net_C# 4.0_Lambda_Expression - Fatal编程技术网

.net 从给定列表中选择包含给定值的动态C#表达式

.net 从给定列表中选择包含给定值的动态C#表达式,.net,c#-4.0,lambda,expression,.net,C# 4.0,Lambda,Expression,我有以下对象结构 public class Client { public Client() { Identifiers = new List<ExternalIdentifier>(); } public Guid? PatientId { get; set; } . . public IList<ExternalIdentifier> Identifiers { get; set; } }

我有以下对象结构

public class Client
{
    public Client()
    {
        Identifiers = new List<ExternalIdentifier>();
    }

    public Guid? PatientId { get; set; }
    .
    .

    public IList<ExternalIdentifier> Identifiers { get; set; }
}
当我运行单元测试时,它构建了以下表达式 s、 标识符.Select(a=>a.Value).ToList()包含(“d”)

但这并没有执行,因为我没有定义“s”,所以非常感谢对构建以下内容的任何帮助

非常感谢s=>s.Identifiers.Select(a=>a.Value).ToList()包含(“d”)


提前感谢。

您非常非常接近获得所需的结果。您只需要为
表达式.Lambda
工厂方法使用定义表达式体时使用的相同
参数Expression
实例参数。将
return
之前方法的最后一行更改为:

var retcontexp = Expression.Lambda<Func<Client, bool>>(contexp, client);
var retcontexp=Expression.Lambda(contexp,客户端);
。。。得到的lambda是有效的,您可以编译它

var retcontexp = Expression.Lambda<Func<Client, bool>>(contexp, client);