Question

I have turned on CA1007 as Error in the ruleset. Then I wrote the below code to violate this rule but it still didn't detect this as either Warning or Error. Not sure where I am making mistake, is it in the code or in the ruleset?

class Program
{
    public static void Swap(ref object object1, ref object object2)
    {
        object temp = object1;
        object1 = object2;
        object2 = temp;
    }

    static void Main(string[] args)
    {
        string string1 = "Swap";
        string string2 = "It";

        object object1 = (object)string1;
        object object2 = (object)string2;
        Program.Swap(ref object1, ref object2);
        string1 = (string)object1;
        string2 = (string)object2;
        Console.WriteLine("{0} {1}", string1, string2);

        Console.ReadLine();
    }
}

Any suggestions? Thanks!

Was it helpful?

Solution

Since Program is a private class (it does not have a modifier on it, so it defaults to private), the public static method is not visible from the outside. The CA1007 is meant to ensure that public API's use a nice signature, but internal, private and otherwise not visible methods are exempt from this rule.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top