I'd like to simplify some code, if possible.
Current Constructor (T is within the scope, defined in the outer type)
public Column(string propertyName)
{
PropertyInfo propertyInfo = typeof(T).GetProperty(propertyName);
_ = propertyInfo ?? throw new ArgumentException(message: $"Property {propertyName} does not exist on {typeof(T).Name}");
...
}
I want to know if it is possible to make property a Lambda expression or something to select the property of Generic Type T.
This of course is to make our development easier with fewer mistakes.
Current use
new DataTable<someClass>.Column(nameof(someClass.someProperty))
I would like to do something like:
new DataTable<someClass>.Column(someClass.someProperty) (without declaring a new someClass)
OR
new DataTable<someClass>.Column(t = > t.someProperty)