From my previous question. C# Linq OrderBy(x => x.property)
I specified my linq orderby argument dynamically.
var param = “attribute1”;
var propertyInfo = typeof(data).GetProperty(param);
List<data> newList = _list
.OrderBy(x => propertyInfo.GetValue(x, null))
.ToList();
the problem is when I want to order this by StringComparison.OrdinalIgnoreCase:
List<data> newList = _list
.OrderBy(x => propertyInfo.GetValue(x, null), StringComparer.OrdinalIgnoreCase)
.ToList();
I receive this error:
The type arguments for method 'System.Linq.Enumerable.OrderBy(System.Collections.Generic.IEnumerable, System.Func, System.Collections.Generic.IComparer)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
By not making it dynamic works. But I want this to order the dynamic argument.
List<data> newList = _list
.OrderBy(x => x.Attribute, StringComparer.OrdinalIgnoreCase)
.ToList();