This project is read-only.

VB ConvertChecked fix

Jun 2, 2011 at 11:09 AM

Hello, Apparantly VB wraps members of type Byte in the "ConvertChecked" function when you access them as part of an Expression/anonymous function/lambda or whatever. This causes GetMemberInfo in ReflectionHelper.cs to throw an exception because it is not expecting a Unary expression (ConvertChecked) in the lambda's body.

I fixed this by making the following change to GetMemberInfo. I don't know if it is a good idea or not, but it works.

private static MemberInfo GetMemberInfo(Type declaringType, Expression expression)
    MemberExpression memberExpression = expression as MemberExpression;
    if (memberExpression == null)
        UnaryExpression convertChecked = expression as UnaryExpression;
        if (convertChecked != null)
            return GetMemberInfo(declaringType, convertChecked.Operand);

        throw new ArgumentException("Expression not supported", "expression");

    return memberExpression.Member;
Nice library btw, goes very well with Moq.