简体   繁体   中英

Code Analysis Warnings in Visual Studio 2010 - CA1007

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM