我有这些枚举:
private enum FontSizeType
{
XSmall, //9
Small, //12
Medium, //18
Large, //24
XLarge, //36
XXLarge //47
}
private enum AlignOptions
{
Left,
Center,
Right
}
private enum ValueType
{
Text,
Barcode
}
Resharper 的检查告诉我所有这些“枚举成员‘XSmall’[等]从未被使用过”
但是我在组合框中使用它们,如下所示:
comboBoxType1.DataSource = Enum.GetNames(typeof(ValueType));
...那么为什么 Resharper 会被愚弄呢?或者是吗?
最佳答案
ReSharper 不检测隐式用法。您可以使用 [UsedImplicitly] 告诉它您的类型成员被隐式使用,然后它应该停止提示。
为了在代码中使用UsedImplicitlyAttribute,您应该包含对JetBrains.Annotations.dll的引用或在项目中包含一些复制粘贴的源代码,请参阅http://www.jetbrains.com/resharper/webhelp/Code_Analysis__Annotations_in_Source_Code.html了解详情。
您应该在每个枚举值上添加 [UsedImplicitly]。
关于combobox - 为什么 Resharper 认为这些枚举从未被使用过?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14884559/