tags:

views:

131

answers:

1

I'm trying to write a rule for fxcop doing this:

if a certain class is compared to null then error.

Do you think it's possible ?

I wrote a part of code descending ti the statements i could find the type i was looking for but didn't know how to find the value.

for know i've got that code but dont know where to go then..

public override ProblemCollection Check(Microsoft.Cci.Member member)
        {
            Method m = member as Method;

            if (m != null)
            {   
                foreach (Statement s in m.Body.Statements)
                {
                    Block b = s as Block;
                    if (b != null)
                    {
                        foreach (Statement s1 in b.Statements)
                        {
                          ?
                        }
                    }
                }
            }

            return this.Problems;
        }
A: 

If you've got reflector, you could take inspiration from the code for Microsoft.FxCop.Rules.Performance.TestForEmptyStringsUsingStringLength - it does something similar to the rule you're looking to write.

marklam