Home >Backend Development >C++ >How Can I Dynamically Order IEnumerable and IQueryable Using String Expressions?
/ iQueryable
When searching for dynamic linq examples, I found that a method can use SQL string (e.g., "Orderby (" Name, Age Desc ")) to sort the IQueryable instance. Is there a way to extend this function to Ienumeration
?
In order to achieve this without using the Dynamic Linq library, the following code fragment provides core expression logic:
This code allows it to sort it by packaging Ienumerationin asquile ().
<code class="language-C#">public static IOrderedQueryable<T> OrderBy<T>( this IQueryable<T> source, string property) { return ApplyOrder<T>(source, property, "OrderBy"); } // ...省略其余代码以简洁起见...</code>Dynamic Linq integrated extension:
This code provides dynamic sorting functions in Linq to Objects.
The above is the detailed content of How Can I Dynamically Order IEnumerable and IQueryable Using String Expressions?. For more information, please follow other related articles on the PHP Chinese website!