How to dynamically use the PropertyType reflection attribute to create a respective typed Function<
Posted
by vsj
on Stack Overflow
See other posts from Stack Overflow
or by vsj
Published on 2010-05-05T18:31:12Z
Indexed on
2010/05/05
18:48 UTC
Read the original article
Hit count: 266
I want to use type returned by PropertyType to create a typed function. I found this similiar http://stackoverflow.com/questions/914578/using-type-returned-by-type-gettype-in-c but this mentions how to create a list but does not mention how we can create a Func<>. Please help me out.
Pseudocode:
PropertyInfo inf = typeof(SomeClass).GetProperty("PropertyName");
Type T=inf.PropertyType;
Expression<Func<SomeClass,T>> le = GetPropertyOrFieldByName<SomeClass, T>("PropertyName");
© Stack Overflow or respective owner