Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.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 如何传递System.Linq.LambdaExpression?_.net_Lambda_Expression Trees - Fatal编程技术网

.net 如何传递System.Linq.LambdaExpression?

.net 如何传递System.Linq.LambdaExpression?,.net,lambda,expression-trees,.net,Lambda,Expression Trees,我有这样一种方法: public List<MyObjects> All<TEntity>(params LambdaExpression[] exprs) All<SomeObject>(a => a.Collection1, a=> a.Collection2, a=>a.Collection3); public List All(参数LambdaExpression[]exprs) 我可以这样称呼它: public List<

我有这样一种方法:

public List<MyObjects> All<TEntity>(params LambdaExpression[] exprs)
All<SomeObject>(a => a.Collection1, a=> a.Collection2, a=>a.Collection3);
public List All(参数LambdaExpression[]exprs)
我可以这样称呼它:

public List<MyObjects> All<TEntity>(params LambdaExpression[] exprs)
All<SomeObject>(a => a.Collection1, a=> a.Collection2, a=>a.Collection3);
All(a=>a.Collection1,a=>a.Collection2,a=>a.Collection3);
但是,我的方法签名似乎没有正确地使用表达式。我做错了什么?如何编写方法签名以获得所需的效果

编辑:我意识到我的示例方法调用并没有准确地反映我在现实生活中试图做的事情:)


谢谢

你的意思是什么

public List<MyObjects> All(params Action<ICollection>[] exprs)

All(a => new List<int>(), b => new List<string>(), c => new List<bool>()); 
public List All(params Action[]exprs)
全部(a=>new List(),b=>new List(),c=>new List());

在这种情况下,最简洁的方法可能是编写一个扩展方法

public static class MyExtensions
{
    public static List<TEntity> All<TEntity, TResult>(
        this TEntity entity,
        params Func<TEntity, TResult>[] exprs)
    {
        if (entity == null)
        {
            throw new ArgumentNullException("entity");
        }
        if (exprs == null)
        {
            throw new ArgumentNullException("exprs");
        }

        // TODO: Implementation required
        throw new NotImplementedException();
    }
}
公共静态类MyExtensions
{
公共静态列表所有(
这个潜在的实体,
参数Func[]exprs)
{
if(实体==null)
{
抛出新的ArgumentNullException(“实体”);
}
if(exprs==null)
{
抛出新的ArgumentNullException(“EXPR”);
}
//TODO:需要实现
抛出新的NotImplementedException();
}
}
请注意,由于类型推断,在调用方法时不必指定类型参数

class C
{
    public List<string> Collection1 {get; set;}
    public List<string> Collection2 {get; set;}
    public List<string> Collection3 {get; set;}
    // ...
}
// ...
var c = new C();            
c.All(x => x.Collection1, x => x.Collection2, x => x.Collection3);
C类
{
公共列表集合1{get;set;}
公共列表集合2{get;set;}
公共列表集合3{get;set;}
// ...
}
// ...
var c=新的c();
c、 全部(x=>x.Collection1,x=>x.Collection2,x=>x.Collection3);

这还不够——因为我需要访问传递到表达式中的“a”对象的属性。动作类不是MVC框架的一部分吗?这没有连接到MVC。
All()
方法应该做什么?是否假设检查集合中的项是否满足一组谓词(类似于LINQ方法)?还是将一组集合展平为一个集合(类似于LINQ方法)?如果我没弄错的话,听起来你应该在这里使用
SelectMany()