c# - Resharper 警告将枚举转换为 UIntPtr,但没有编译器警告

标签 c# resharper resharper-7.1

在下面的代码中,Resharper 给我一个警告:Cannot cast expression of type 'Color' to type 'UIntPtr'。 (实际上,Resharper 认为这是一个实际错误。)

但是,没有编译器警告,它工作正常。

在我看来,这像是一个 Resharper 错误。是吗?还是编译器不担心它有什么不好的地方? (我使用的是 Resharper 7.1.1)

using System;

namespace Demo
{
    internal class Program
    {
        public enum Color { Red, Green, Blue }

        private static void Main(string[] args)
        {
            UIntPtr test = (UIntPtr) Color.Red; // Resharper warning, no compile warning.
        }
    }
}

我可以通过先将值转换为 int 来使警告消失,所以我有一个解决方法:

UIntPtr test = (UIntPtr)(int) Color.Red;

最佳答案

This looks like a Resharper bug to me. Is it?

Yes :

RSRP-78748 False 'conversion does not exist' (UIntPtr)

using System;

class A
{
    static void Main()
    {
        E? x = 0;
        UIntPtr z = (UIntPtr)x;
    }
}
enum E { }

It is a known spec devation.

截至 2013 年 3 月 5 日尚未修复。

关于c# - Resharper 警告将枚举转换为 UIntPtr,但没有编译器警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15222343/

相关文章:

c# - c#中的视频通话

javascript - 方法如何将 null 作为接口(interface)返回

unit-testing - ReSharper执行单元测试的控制顺序

extjs - 你如何使用 Jasmine + Resharper 引用外部库

c# - ReSharper 生成此文件 : Annotations. cs。为什么?

javascript - 为什么这些 resharper Jasmine 测试在浏览器中运行而不是在 phantomjs 中运行

c# - 在 c# .net webservice 中替换 http 请求正文中的无效字符

c# - .NET Core 的枚举反射

c# - 在关闭表单之前停止线程

c# - 事件方法的 ReSharper 命名风格