T は、特定のプロパティを持つ場合と持たない場合がある型です。「City」としましょう。「City」という名前のプロパティを持つ型については、Gotham の住民のみが返され、並べ替えられるようにレコードを制限したいと思います。
public static IQueryable<T> OrderBy<T>(this IQueryable<T> source, string ordering, params object[] values) 
{
    var type = typeof(T);
    var property = type.GetProperty(ordering);
    var parameter = Expression.Parameter(type, "p");
    var propertyAccess = Expression.MakeMemberAccess(parameter, property);
    var orderByExp = Expression.Lambda(propertyAccess, parameter);
    MethodCallExpression resultExp = Expression.Call(
                typeof(Queryable), 
                "OrderBy", 
                new     Type[] { type, property.PropertyType }, 
                source.Expression, 
                Expression.Quote(orderByExp));
    string propertyToRestrictOn = "City";
    string restrictedValue = "Gotham";
    var restrictedProperty = type.GetProperty(propertyToRestrictOn);
    if(null ! = restrictedProperty )
    {
      // TODO: What to add here so than only those records are returned that have a 
      // property named City and the value is 'Gotham'???
    }
   return source.Provider.CreateQuery<T>(resultExp);
}
可能であれば、より複雑なクエリを作成する必要がある場合に備えて、ここでいくつかの役立つ文献に名前を付ける/リンクしてください。つまり、And/OR を組み合わせます。
このコードは、汎用拡張メソッド内で文字列列名を使用して IQueryable に OrderBy を適用するにはどうすればよいですか?から借用し たものです。