Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Contract for Enum.GetName incorrectly states result not null #478

Open
NameOfTheDragon opened this issue Jan 21, 2017 · 0 comments
Open

Comments

@NameOfTheDragon
Copy link

When building I get an incorrect warning about possible 'dead code' for the following IF statement:

            foreach (char c in text)
                {
                var b = (byte)c;
                var strASCII = Enum.GetName(typeof(AsciiSymbols), b);
                if (strASCII != null)
                    expanded.Append("<" + strASCII + ">");
                else
                    expanded.Append(c);
                }

The problem seems to be an incorrect contract for Enum.GetName():
image

An examination of the source code shows that the result can in fact be null, so this is leading to a false positive in the warning.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant