combobox - 为什么 Resharper 认为这些枚举从未被使用过?

标签 combobox enums resharper datasource automated-refactoring

我有这些枚举:

    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/

相关文章:

sql - VB |将 SQL 查询加载到 Combobox

android - 如何在 proguard 中保留 Enum 类型字段?

c# - 为 View 创建或数据库存储定义选择/下拉选项的最佳实践方法是什么

visual-studio-2010 - 调试 Visual Studio 扩展性能问题

wpf - 使用 MVVM 解决 Combobox 交互

java - 使用枚举组合框中的值作为 setter 的参数

delphi - 组合框:每个项目上都有一个按钮(用于从列表中删除项目)

c++ - 使用枚举实例化模板

c# - ReSharper [CanBeNull] 和 [NotNull] 属性可以应用于 Action 或 Func 参数吗?

c# - 在 Visual Studio 2012 中折叠所有 #region