Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.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# Func<;T、 布尔>;延长条件_C#_Asp.net_.net_.net Core - Fatal编程技术网

C# Func<;T、 布尔>;延长条件

C# Func<;T、 布尔>;延长条件,c#,asp.net,.net,.net-core,C#,Asp.net,.net,.net Core,我有一个接受Func条件作为参数的方法,我想将条件展开如下: public T SomeClass.GETConditionalValue(x=>x.Id==id).ToList(); 现在,这个SomeClass.GETConditionalValue需要一个参数Func条件 我想在不干扰SomeClass.GETConditionalValue 大概是这样的: public T SomeClass.GETConditionalValue(ApplyFilter(x=>x.Id=

我有一个接受
Func
条件作为参数的方法,我想将条件展开如下:

public T SomeClass.GETConditionalValue(x=>x.Id==id).ToList();
现在,这个
SomeClass.GETConditionalValue
需要一个参数
Func
条件 我想在不干扰
SomeClass.GETConditionalValue

大概是这样的:

public T SomeClass.GETConditionalValue(ApplyFilter(x=>x.Id==id)).ToList();
public Func<T, bool> ApplyFilter<T>(Func<T, bool> condition) where T: GenericClass
{
    return t => condition(t) (+ some new condition in & or || block) 
}
在哪里

public FuncApplyFilter(Funccondition),其中T:GenericCLass
{
返回条件(+在&或| |块中的某些新条件)
}
**更新:-**此处无法使用委托,无法将lemda表达式转换为bool类型,因为它不是deligate类型

   public IEnumerable<T> GetEntities<T>(Func<T, bool> condition) where T : ITableEntity, new()
        {
            if (applicationFilter == null)
                return tableContext.CreateQuery<T>().Where(condition).ToList();
            return tableContext.CreateQuery<T>().Where(applicationFilter).Where(condition).ToList();
        }
 
public IEnumerable GetEntities(Func条件),其中T:ITableEntity,new()
{
if(applicationFilter==null)
返回tableContext.CreateQuery().Where(condition.ToList();
返回tableContext.CreateQuery().Where(applicationFilter).Where(condition).ToList();
}
我的电话是

 var mappedApplications = userToMdouleRepo.GetEntities<UserMappingToModules>(x => x.UserEmail == email)
var-mappedApplications=userToMdouleRepo.GetEntities(x=>x.UserEmail==email)
我想把它改成这样

 var mappedApplications = userToMdouleRepo.GetEntities<UserMappingToModules>(ApplyAdditionalFilter(x => x.UserEmail == email)).ToList()
var-mappedApplications=userToMdouleRepo.GetEntities(applyaadditionalfilter(x=>x.UserEmail==email)).ToList()

您可以这样做:

public T SomeClass.GETConditionalValue(ApplyFilter(x=>x.Id==id)).ToList();
public Func<T, bool> ApplyFilter<T>(Func<T, bool> condition) where T: GenericClass
{
    return t => condition(t) (+ some new condition in & or || block) 
}
public Func ApplyFilter(Func条件),其中T:GenericClass
{
返回t=>条件(t)(+在&或| |块中的一些新条件)
}
例如:

public class GenericClass
{
    public string Name { get; }
}

public Func<T, bool> ApplyFilter<T>(Func<T, bool> condition) where T: GenericClass
{
    return t => condition(t) && t.Name == "SomeName";
}
公共类GenericClass
{
公共字符串名称{get;}
}
公共函数ApplyFilter(函数条件),其中T:GenericClass
{
返回t=>condition(t)&&t.Name==“SomeName”;
}

换句话说,
ApplyFilter
将返回一个委托?是的,问题是您可以像(条件&&x=>x.Name==“Hi”)那样展开函数条件@Fildor我不能使用deligate你使用的是deligate:我的意思是我继续扩展条件它的抛出错误未工作mate无法将lemda表达式转换为bool类型,因为它不是deligatetype@RAHULSR你能邮寄你的lambda吗?这绝对应该编译:请看它now@RAHULSR我指的是您的
ApplyFilter
实现,即导致编译器错误的位置。@没有问题,没有继承ITableEntity的ApplicationBaseEntity,因此,我的筛选方法也使用ApplicationBaseEntity