Linq access property by variable

You can write an extension method

public static class MyExtensions
{
    public static object GetProperty<T>(this T obj, string name) where T : class
    {
        Type t = typeof(T);
        return t.GetProperty(name).GetValue(obj, null);
    }
}

and use it like this

var x = myList.Where(f => f.GetProperty("Title") == myValue);

Leave a Comment