我们最近将一个旧的 C# 应用程序从 Visual Studio 2003 移植到了 Visual Studio 2010。
在搜索代码中要清理的东西时,我在上面运行了 Resharper,它告诉我(很多次),“对未由 [Flags] 属性标记的枚举进行按位操作”
例如,这里有一段代码用该消息“标记”(不是双关语):
~DuckbillConverter()
{
//stop running thread
if((this.Status & ConvertStatus.Running) == ConvertStatus.Running)
this.Stop();
}
我假设此代码按原样工作;那么按照 R# 的建议,使用 [Flags] 属性装饰 ConvertStatus.Running 会有什么好处(或者更重要的是,任何可能的副作用)?
更新
对乔恩斯基特的回答:
public enum ConvertStatus
{
/// <summary>
/// The thread is not running, there are no manual conversions or purges and no errors have occurred.
/// </summary>
Stopped = 0x0,
/// <summary>
/// The thread is running and will automatically convert all sites for both file types.
/// </summary>
Running = 0x1,
/// <summary>
/// A data conversion is currently taking place.
/// </summary>
Converting = 0x2,
/// <summary>
/// A data purge is currently taking place.
/// </summary>
Purging = 0x4,
/// <summary>
/// An error has occurred. Use the LastError property to view the error message.
/// </summary>
Error = 0x8
}