B. *_*non 5 c# resharper enums bit-manipulation
我们最近将一个旧的C#应用程序从Visual Studio 2003移植到Visual Studio 2010.
在搜索代码中要清理的东西时,我在上面运行了Resharper,它告诉我(很多次),"枚举上的按位操作没有标记[Flags]属性"
例如,这里有一些代码,它用该消息"标记"(没有双关语):
~DuckbillConverter()
{
//stop running thread
if((this.Status & ConvertStatus.Running) == ConvertStatus.Running)
this.Stop();
}
Run Code Online (Sandbox Code Playgroud)
我假设这段代码按原样运行; 那么,如果R#建议用[Flags]属性装饰ConvertStatus.Running会有什么好处(或者更重要的是,任何可能的副作用)?
回答Jon Skeet:
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
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2707 次 |
| 最近记录: |