Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取并设置属性FxCop规则_C#_Visual Studio 2010_Fxcop_Static Code Analysis - Fatal编程技术网

C# 获取并设置属性FxCop规则

C# 获取并设置属性FxCop规则,c#,visual-studio-2010,fxcop,static-code-analysis,C#,Visual Studio 2010,Fxcop,Static Code Analysis,因此,我正在编写一个自定义Fxcop规则,以确保无论何时使用Get或Set方法,其中都有一个GetProperty或SetProperty。我怎样才能测试这个 例如: public double Seconds { get { return this.GetProperty(() => this.Seconds); } set { this.SetProperty(() => this. Seconds, value); } } 与此相反: public double

因此,我正在编写一个自定义Fxcop规则,以确保无论何时使用Get或Set方法,其中都有一个GetProperty或SetProperty。我怎样才能测试这个

例如:

public double Seconds
{
   get { return this.GetProperty(() => this.Seconds); }
   set { this.SetProperty(() => this. Seconds, value); }
}
与此相反:

public double Seconds
{
    get { return Seconds; }
    set { Seconds = value; }
}
到目前为止,我可以用这段代码找到get或set的每个实例。我只是需要帮助捕捉是否确实存在GetProperty或SetProperty

    public override ProblemCollection Check( Member member )
    {
        ProblemCollection Problems = this.Problems;

        var method = member as Method;

        if ( method != null )
        {
            if ( method.Name.Name.Contains( "get_" ) || method.Name.Name.Contains( "set_" ) )
            {
                Resolution resolu = GetResolution( new[] { member.ToString() } );
                Problems.Add( new Problem( resolu ) );
                return Problems;
            }
        }
        return null;
    }
}

我很好奇-这条规则的优点是什么(因为它对我来说是新的)?我们在新的框架中定义了GetProperty和SetProperty,我们正在向我们的开发人员推出,我们希望这成为一个标准。您是指可用的
GetProperty
/
SetProperty
方法,还是实际使用的方法?顺便说一句,为什么你的
SetProperty
方法不赋值呢?看起来有点奇怪。您添加了另一个不必要的间接级别。“公共双秒{get;set;}”有什么问题?简单得多。编译器将自动为您生成get和set方法。为什么添加另一个级别的get/set方法却没有任何好处?您是否分析了您的方法以了解开销是多少?我认为您可能有点困惑。GetProperty是我们框架中的一个自定义方法,在使用Get方法时调用它。我很好奇-这个规则的优点是什么(因为它对我来说是新的)?我们在新的框架中定义了GetProperty和SetProperty,我们正在向开发人员推出这一框架,我们希望它成为一个标准。您是指可用的
GetProperty
/
SetProperty
方法,还是实际使用的方法?顺便说一句,为什么你的
SetProperty
方法不赋值呢?看起来有点奇怪。您添加了另一个不必要的间接级别。“公共双秒{get;set;}”有什么问题?简单得多。编译器将自动为您生成get和set方法。为什么添加另一个级别的get/set方法却没有任何好处?您是否分析了您的方法以了解开销是多少?我认为您可能有点困惑。GetProperty是我们框架中的一个自定义方法,在使用Get方法时调用它。