I want to disallow calls to a specific method (MessageBox.Show) via a custom FxCop rule. I know the mechanics of how to get an FxCop rule custom-implemented (the XML file, inheriting from BaseIntrospectionRule, etc.) My question here is what I put in the "Check" method.
Below is the initial draft I have based on poking around a lot on the web, but I'm very puzzled as to what I would actually populate in the two fields marked with ????? below.
I'm not sure even this solution, as it exists, would work. What is the fool-proof to make sure I'm doing what I want -- which is catching all calls to MessageBox.Show?
public override ProblemCollection Check(Member member)
{
Method method = member as Method;
if (method == null)
{
return null;
}
MetadataCollection<Instruction>.Enumerator enumerator = method.Instructions.GetEnumerator();
while (enumerator.MoveNext())
{
Instruction current = enumerator.Current;
switch (current.OpCode)
{
case OpCode.Call:
case OpCode.Callvirt:
{
Method method3 = current.Value as Method;
if (method3 == **?????**)
{
Problem item = new Problem(base.GetResolution(**?????**), current);
base.Problems.Add(item);
}
break;
}
}
}
return base.Problems;
}