ardalis / ardalis/SmartEnum

FronValue not working when value is a custom object

Open
#90 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
2.4k
Forks
184
PR merge metrics
No merged PRs in 30d

Description

Hello,
I have
LieuxDeStationnement : SmartEnum
so the "value" is of type LieuDeStationnementKey.

LieuDeStationnementKey implements IEquatable and IComparable with also operators (== != < >)

I tried this

try
{
LieuDeStationnementKey ley1 = LieuxDeStationnement.Peseux.Value; // this is {"NE",6421}
LieuxDeStationnement lieu1 = LieuxDeStationnement.FromValue(ley1); // this functions ok.
LieuDeStationnementKey lieuKey = OtherObject.LieuDeStationnementKey; // this is {"NE",6421}
LieuxDeStationnement lieu = LieuxDeStationnement.FromValue(lieuKey); // this give NotFound
}
catch (Exception e)
{
throw;
}

I joind the zip with the two classes.
ALso I see that FromValue doesn't call any of the IEquatable, IComparable methods ... so I don't understand how it works.

[LieuDeStationnementKey.zip](https://github.com/ardalis/SmartEnum/files/4953472/LieuDeStationnementKey.zip)

Contributor guide

Open the contributing guide

Research direction

Start by inspecting the two classes in the attached LieuDeStationnementKey.zip and tracing the FromValue entry point. Reproduce the difference between the value from LieuxDeStationnement.Peseux and OtherObject.LieuDeStationnementKey, then determine how custom-object equality is expected to affect the lookup and capture the behavior in a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.