所以我正在编写一个自定义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;
}
}