Comments (12)
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.
Merged - I'll try to publish a new build to Nuget soon. Thanks!
from smartenum.
Something like TestEnum.One == myEnumVar
?
Sounds like a great idea to me.
from smartenum.
Iād definitely consider a PR with this, thanks!
from smartenum.
Cool! I'll have a look at it somewhere in the next days.
@yarrgh Exactly. :)
from smartenum.
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.
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.
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.
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.
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.
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.
What, a month seems like too long for me to look at this? ;)
from smartenum.
Related Issues (20)
- Ordering the values
- Can/should SmartEnum implement the non-generic IComparable interface?
- SmartEnumStringComparer not included in 7.0.0 version HOT 2
- Add a ValidationAttribute to Validate Model Property Against SmartEnum Names
- ushort error in SmartFlagEnumValueConverter HOT 1
- For the README.md I found out that the path for TestEnum.cs is broken HOT 1
- Add Description attribute HOT 1
- Please Release Version for .NET 8.0 HOT 3
- Are you open to a PR for a nullable `Name`? HOT 2
- Add a way to enumerate over the List to prevent allocation every time List is called HOT 2
- Support for a default enum value?
- Add support for NRT HOT 1
- Revert PR 412 and remove support for null values. HOT 1
- eliminate explicit dependency for STJ on newer frameworks HOT 7
- Use canonical null checks.
- Json Serializer
- Avoid creating a new list on SmartEnum.List HOT 3
- Add Guard fro SmartEnum Out of Range HOT 2
- FromValue documentation specifies that the wrong exception is thrown
- Would it be possible to support netstandard2.0 instead of netstandard2.1?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from smartenum.