VisitMethodCall

Hi Friends,

I realized that when looping on InstructionList I have SourceContext working, but how I get SourceContext working from inside an overrided VisitMethodCall or other Visit*?

Any directions please?

Thanks in advance

Washington Moreira

[277 byte] By [WashingtonMoreira] at [2007-12-22]
# 1

Look at the relevant SourceContext hanging off the node you're visiting. These are only sparsely populated, currently, due to an incompleteness in the metadata reader. We've fixed this in FxCop 1.36 but, as always, I have to warn you that writing against the Method.Body is a guarantee of future breaking changes. We are working with a couple of teams internally right now to define the right method body representation for analysis. The current one is problematic, due to its nesting. You might have noticed this when analyzing calls that has arguments which are calls themselves.

One workaround you can use is to override every node visit and collect its source context, if available. In this way, you'll always have the last encountered source context to associate with a violation that you raise. We used this approach ourselves in FxCop until the recent fix we made in the reader.



public override Node Visit(Node node)
{
if (node.SourceContext.Document != null)
this.m_sourceContext = node.SourceContext;
return base.Visit(node);
}

MichaelFanning-MS at 2007-8-30 > top of Msdn Tech,Visual Studio Team System,Visual Studio Code Analysis and Code Metrics...
# 2

Thanks Michael

Washington Moreira

WashingtonMoreira at 2007-8-30 > top of Msdn Tech,Visual Studio Team System,Visual Studio Code Analysis and Code Metrics...

Visual Studio Team System

Site Classified