Forwarding warning message to UIntPtr but compiler warning

The following code Resharper gives me a warning: Cannot cast expression of type 'Color' to type 'UIntPtr'. (In fact, Resharper considers this a factual error.)

However, the compiler does not warn and works fine.

It looks like a Resharper bug for me. It? Or is there something bad about this that the compiler is not worried about? (I am using 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.
        }
    }
}

I can make a warning by removing the value first in int, so I have a workaround:

UIntPtr test = (UIntPtr)(int) Color.Red;
+5
source share
1 answer

It looks like a Resharper bug for me. 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 { }

This is a well-known specification.

2013-03-05.

+3

All Articles