mercredi 26 août 2020

How can I put && condition in LINQ with reflection in C#?

public class Exclusion
{
    public ICollection<KeyValues> Exclusionproperties{get;set;}
    public string Display_value{get;set;}
}

public class KeyValues
{
public string Key {get;set;}
public ICollection<string> Values{get;set;}
}

public IQueryable<T> ExcludeFromResult<T>(IQueryable<T> result, ICollection<Exclusion> exclusions)
{
       foreach(var ex in exclusions)
      {
         foreach(var p in ex.ExcludedProperties)
         {
            result = result.Where(x=>!p.Values.Contains(x.GetType().GetProperty(p.Key).GetValue(x).ToString()));
         }
      }
}

this above code will work fine if excludedproperties have just one property. But if it has more than 1 property than I would like to have a condition in where with &&. Can somebody please help how to do this?





Aucun commentaire:

Enregistrer un commentaire