I am trying to write a function that will pull the name of a property and the type using syntax like below:
private class SomeClass { Public string Col1; } PropertyMapper<Somewhere> propertyMapper = new PropertyMapper<Somewhere>(); propertyMapper.MapProperty(x => x.Col1)
Is there any way to pass the property through to the function without any major changes to this syntax?
I would like to get the property name and the property type.
So in the example below i would want to retrieve
Name = 'Col1' and Type = 'System.String'
Can anyone help?
Here’s enough of an example of using Expressions to get the name of a property or field to get you started:
Calling code would look like this:
A word of caution, though: the simple statment of
(Program p) => p.Nameactually involves quite a bit of work (and can take measurable amounts of time). Consider caching the result rather than calling the method frequently.