-
-
Notifications
You must be signed in to change notification settings - Fork 173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Equals implementation #20
Comments
Something like Sounds like a great idea to me. |
I’d definitely consider a PR with this, thanks! |
Cool! I'll have a look at it somewhere in the next days. @yarrgh Exactly. :) |
After thinking about this a bit more doesn't 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. |
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. |
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. :) |
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. |
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. |
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 Feel free to let me know if there are other ideas about doing this. :) |
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. :) |
What, a month seems like too long for me to look at this? ;) |
Merged - I'll try to publish a new build to Nuget soon. Thanks! |
I was wondering if it would make sense to override and implement
Equals()
for theSmartEnum
. Because now, if I'm checking for equality, I'm doing something likeTestEnum.One.Value == myEnumVar.Value
, which is not only a little more tedious, but you can also make mistakes.If the answer is positive, I could try to do this myself and send a PR your way, if you like. :) In that case, I would have one question about what would be "the right way": two
SmartEnum
instances would be considered equal if theirName
property is equal, right (and not necessarily theirValue
property, as in my example)?Thanks by the way for providing this! I really like to use it. :)
The text was updated successfully, but these errors were encountered: