Giter Site home page Giter Site logo

Comments (9)

CyrusNajmabadi avatar CyrusNajmabadi commented on July 23, 2024 1

There should be a fix offered here.

from roslyn.

jjonescz avatar jjonescz commented on July 23, 2024

The warning is correct, you can do this:

Orientation orientation = (Orientation)3;

from roslyn.

SetTrend avatar SetTrend commented on July 23, 2024

@jjonescz: You could also do anything that's valid for an integer. Yet, who would do that?

I don't think it's reasonable to warn about hypothetical assignments. It would make more sense to warn about assigning invalid values to an enum type.

from roslyn.

jjonescz avatar jjonescz commented on July 23, 2024

I don't think it's reasonable to warn about hypothetical assignments.

In that case you should suppress the warning for your whole project or solution.

It would make more sense to warn about assigning invalid values to an enum type.

There might be an analyzer for that. But it's an explicit cast, so it should be obvious you are doing something advanced and warning doesn't seem necessary.

Otherwise this is a language design question, those should be discussed in https://github.com/dotnet/csharplang first. Thanks!

from roslyn.

SetTrend avatar SetTrend commented on July 23, 2024

With all due respect, the current warning text doesn't make any sense to this regard.

In the end, it all boils down to "add an anonymous switch case". Period. Nothing else.

Anything else, like the current "you are missing this or that value" endlessly is just a ridiculous cat-and-mouse game. You would end up adding 32768 switch cases.

Have you ever thought about providing a quick fix for remedying this warning by adding all the corresponding switch cases? The current warning message ("you are missing a particular value") is plain nonsense.

from roslyn.

jaredpar avatar jaredpar commented on July 23, 2024

re-open for IDE fixer

from roslyn.

Cosifne avatar Cosifne commented on July 23, 2024

New feature/Temp put under Sam's bucket because it's related to CodeStyle.

from roslyn.

sharwell avatar sharwell commented on July 23, 2024

@CyrusNajmabadi It seems like the fix here is project specific. For example, in Roslyn the fix would be throwing ExceptionUtilities.UnexpectedValue, but that method doesn't exist generally.

from roslyn.

sharwell avatar sharwell commented on July 23, 2024

After reviewing the SharpLab output for the original code sample, I'm doubting our ability to improve upon the current behavior. Before implementing a code fix, I would need to see a proposed code fix that achieves the following:

  1. The performance matches the current behavior (the exception is thrown from a different method, or the use of a throw helper is known to no longer provide specific value)
  2. The exception type and message is of similar quality to the current one
  3. The clarity of the switch expression is not negatively impacted

from roslyn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.