LINQ: “contains” and a Lambda query

后端 未结 6 1505
庸人自扰
庸人自扰 2020-12-13 01:07

I have a List called buildingStatus. I\'d like to check whether it contains a status whose char code (returned by GetCh

6条回答
  •  再見小時候
    2020-12-13 01:41

    If I understand correctly, you need to convert the type (char value) that you store in Building list to the type (enum) that you store in buildingStatus list.

    (For each status in the Building list//character value//, does the status exists in the buildingStatus list//enum value//)

    public static IQueryable WithStatus(this IQueryable qry,  
    IList buildingStatus) 
    { 
        return from v in qry
               where ContainsStatus(v.Status)
               select v;
    } 
    
    
    private bool ContainsStatus(v.Status)
    {
        foreach(Enum value in Enum.GetValues(typeof(buildingStatus)))
        {
            If v.Status == value.GetCharValue();
                return true;
        }
    
        return false;
    }
    

提交回复
热议问题