简体   繁体   English

Visual Studio 2010中的代码分析警告-CA1007

[英]Code Analysis Warnings in Visual Studio 2010 - CA1007

I have turned on CA1007 as Error in the ruleset. 我已在规则集中将CA1007设置为“错误”。 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. 由于Program是私有类(它上没有修饰符,因此默认为私有),因此从外部看不到public static方法。 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. CA1007旨在确保公共API使用良好的签名,但内部,私有和其他不可见方法不受此规则CA1007

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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