Thursday, November 1, 2007

MemberExpression Question

Maybe someone can answer this for me. When C# is compiled into an Expression tree, the MemberInfo that is tied to a MemberExpression points to the most virtual/abstract definition of that member. For an example, take a look at this code. The Visitor class will print the declaring type of a member encountered in a MemberAccess Expression (ln 36). When ran in Orcas B2, it prints "BaseClass" rather than "ConcreteClass". Is this how it's supposed to behave? Does Mono behave this way? Is there a better way to get the MethodInfo of the concrete class than this:

// This goes in the Visitor.VisitMemberAccess method
MemberInfo mi = m.Expression.Type.GetMemeber(m.Member.Name)[0];

I ask because I'm looking for custom attributes which may only exist on the overridden members of the concrete classes.