Code Monkey home page Code Monkey logo

Comments (12)

trevor-hackett avatar trevor-hackett commented on September 1, 2024 1

To be safe, it might be best to compare the value.

I'm just remembering that an empty constructor was added to play nice with Entity Framework which, I believe, creates a new instance of the SmartEnum (see #15). In this case comparing by reference would be incorrect.

from smartenum.

ardalis avatar ardalis commented on September 1, 2024 1

Merged - I'll try to publish a new build to Nuget soon. Thanks!

from smartenum.

trevor-hackett avatar trevor-hackett commented on September 1, 2024

Something like TestEnum.One == myEnumVar?

Sounds like a great idea to me.

from smartenum.

ardalis avatar ardalis commented on September 1, 2024

Iā€™d definitely consider a PR with this, thanks!

from smartenum.

DeveTho avatar DeveTho commented on September 1, 2024

Cool! I'll have a look at it somewhere in the next days.

@yarrgh Exactly. :)

from smartenum.

trevor-hackett avatar trevor-hackett commented on September 1, 2024

After thinking about this a bit more doesn't TestEnum.One == myEnumVar already work?

Unless you're newing up objects outside of the static readonly properties, this should work. By default the framework compares the reference of objects unless explicitly overridden. Since they are pointed to the same instance of the object the equals check would run correctly.

from smartenum.

ardalis avatar ardalis commented on September 1, 2024

It probably should. Not sure if we have tests that demonstrate this is the case already. If not, we should at least add such tests, so there's no question.

from smartenum.

DeveTho avatar DeveTho commented on September 1, 2024

Hmm, yeah, it should be the same reference. But would it be okay then to just compare by reference, and not the actual value (in case the tests would show it does work)? In that case, it should probably also be documented in the README, as it's a quite implicit thing.

Though I'm probably already thinking ahead a little. I'll try to have a look at it and let you know about and show what I found. :)

from smartenum.

DeveTho avatar DeveTho commented on September 1, 2024

Just thought to quickly let you know I haven't further looked into it yet, sorry. But I didn't forget about it!

Also, thanks for the remarks on the EF constructor.

from smartenum.

DeveTho avatar DeveTho commented on September 1, 2024

I just created a pull request #22 that provides this feature, I hope in a good way.

For tests, I only added some that check different instances of the SmartEnum (like when using EF). Checks by reference are already done in other tests, like SmartEnumExplicitConversion.

Feel free to let me know if there are other ideas about doing this. :)

from smartenum.

DeveTho avatar DeveTho commented on September 1, 2024

I thought to quickly give a heads-up that if there's something I can do still regarding this issue / feature, feel free to let me know. Otherwise I'll just wait for feedback. :)

from smartenum.

ardalis avatar ardalis commented on September 1, 2024

What, a month seems like too long for me to look at this? ;)

from smartenum.

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.