Suggestion for improvement of Typed Reflector

Mar 10, 2010 at 4:11 PM


I just checked out the source code of the Typed Reflector. After some investigation how it works, I have seen two little improvements that could be made.

1. Why not define a TResult for GetProperty and GetField instead of using object. The TResult type must not be supplied explicitly when using it. It is inferred by the compiler. The usage of the TResult type parameter would remove the occurrence of the UnaryCastExpression in the Expression Tree if the property is a value type.

public static PropertyInfo GetProperty<TResult>(Expression<Func<TTarget, TResult>> property)
public static FieldInfo GetField<TResult>(Expression<Func<TTarget, TResult>> field)


2. The type of the parameter in the private static methods that return the Member / Method Info instance could be changed to LambdaExpression. The Expression<TDeleagate> type used in the public methods inherits from LambdaExpression. With this change you can remove the check for LambdaExpression.

private static MemberInfo GetMemberInfo(LambdaExpression member)
private static MethodInfo GetMethodInfo(LambdaExpression method)


What do you think about those changes?

Thanks, Marco

Mar 10, 2010 at 6:34 PM

great suggestions! making the changing in my code right away :)