Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.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
动态对象上的C#动态表达式_C#_Expression_Expression Trees - Fatal编程技术网

动态对象上的C#动态表达式

动态对象上的C#动态表达式,c#,expression,expression-trees,C#,Expression,Expression Trees,让我们假设以下场景: 我有两门课: public class Customer { public string Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } } public class Employee { public string Id { get; set; } public string FirstName

让我们假设以下场景:

我有两门课:

public class Customer
{
    public string Id { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
}


public class Employee
{
    public string Id { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public int Age { get; set; }
}
然后我可以:

List<Customer> customers = new List<Customer>();

List<Employee> employees = new List<Employee>();
另外,我希望能够自动从动态对象中提取属性,因为您可以看到这两个类具有相同的属性,但也有一些不同的属性

谁能给我指一下正确的方向吗

我需要的是类似TFS的东西:

您可以使用它。它允许您组合一个表达式树并编译它,然后您可以在使用lambdas的任何地方使用if作为
Func
Action

或者,如果您不编译它,您可以用任何其他方式解释或检查它


有一些开放源码项目允许您序列化和反序列化表达式,但我没有使用过,因此无法提出建议。

Wow相关问题今天很重要,给你:阅读以下内容,例如,如何在数据库中持久化表达式?我想表达式可以是一个对象,使用属性,当然在这种情况下,它可以序列化。。。正确的?
public static List<Employee> GetMajorEmployees(this List<Employee> employees)
{
    return employees.Where(t=>t.Age >= 18).ToList();
}
 public static List<T> RunCustomQuery<T>(this List<T> items, dynamic query)
{
    return items.ExecuteQuery(query); // to be implemented
}
customers.Where(t=>t.FirstName == "Jhon");