I must create similar to Fluent API. I have DTO:
public class Foo { public string Bar {get;set;} }
And i need to provide some properties (for example column name):
new MyFluentApi<Foo>().ColumnAttributes(**p => p.Bar**).ColumnName("Some very long column name where are Bar values")
In ColumnAttributes i need to get Type/name of specified property, but how? In expression p => p.Bar i get actual value of Bar, but i need type
Like this:
Note that if your lambda isn't a straight property access this will throw an exception.
An alternative would be to use type inference:
Now this should work with any expression, regardless as to whether a property is accessed, which may or may not be what you're after.
For example, this would run without exception: