小编Joh*_* K.的帖子

动态列表<T>的位置

我正在尝试为各种类创建动态过滤器.我们只会在运行时知道我们正在处理什么类型.我需要ColumnName作为实际列(不是字符串值).

有没有一种简单的方法将字符串转换为列?

public static List<T> Filter<T>
    (this List<T> Source, string ColumnName, 
    string TypeOfCompare, string CompValue)
{
    IQueryable<T> matches = Source.AsQueryable();

    if (ColumnName.Length > 0)
    {
        matches = (IEnumerable)matches.Where(a => ColumnName == CompValue)
    }

    List<T> ReturnList2 = new List<T>();
    ReturnList2 = matches.ToList();
    return ReturnList2;
}
Run Code Online (Sandbox Code Playgroud)

c# linq-to-entities

6
推荐指数
1
解决办法
3869
查看次数

标签 统计

c# ×1

linq-to-entities ×1