I have created an FxCop rule that checks for DateTime.Now use. It works pretty well, except that it reports the offending line number as the start of the method, rather than the line of code that actually calls DateTime.Now. What do I need to do to get the right line number in the FxCop report. Here's my code:
public override void VisitMemberBinding(MemberBinding memberBinding)
{
string name = memberBinding.BoundMember.FullName;
if (name == "System.DateTime.get_Now")
{
Problems.Add(new Problem(GetResolution(), memberBinding.BoundMember.SourceContext));
}
base.VisitMemberBinding(memberBinding);
}
I've tried memberBinding.SourceContext and memberBinding.BoundMember.SourceContext and both return the method's start line number.
I could use SourceContext.(Start|End)LineNumber but which one? Seems that I am just not using the correct object.SourceContext