If you do not need to specify the property name as a string, it is quite simple using dynamic :
List<object> l = FillList(); l = l.OrderBy(o => ((dynamic)o).Id);
If the property name should be a string, then it becomes a little more complicated, but can be done using reflection (although it is not very efficient):
l = l.OrderBy(o => o.GetType() .GetProperty("Code") .GetValue(o, null));
You should also consider adding some error handling, for example. if the property does not exist.
In addition, if all the items in the list have the same type of run time, it would be much more efficient to compile the getter function using expression trees and reuse (instead of directly using reflection).
public static Func<object, object> CreateGetter(Type runtimeType, string propertyName) { var propertyInfo = runtimeType.GetProperty(propertyName);
and use it like:
var codeGetter = CreateGetter(l[0].GetType(), "Code");
source share