-
Notifications
You must be signed in to change notification settings - Fork 309
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
EnumValueObject
- Allow for int
and implementation example?
#479
Comments
int
and implementation example?EnumValueObject
- Allow for int
and implementation example?
It seems that the Here is my implementation: // As regular class, see sealed implementation below
public class VoteDirection : EnumValueObject<VoteDirection, int>
{
public static readonly VoteDirection Neutral = new VoteDirection(1, nameof(Neutral));
public static readonly VoteDirection DownVote = new VoteDirection(2, nameof(DownVote));
public static readonly VoteDirection UpVote = new VoteDirection(3, nameof(UpVote));
/// <inheritdoc />
protected VoteDirection(int id,
string name)
: base(id, name)
{
}
} Just posting this here so that when devs search for 'Issues', this result will be available. 1.) How is my implementation? 2.) Should my parent class of 3.) Would it be possible to use Implementation as public sealed class VoteDirection : EnumValueObject<VoteDirection, int>
{
public static readonly VoteDirection Neutral = new VoteDirection(1, nameof(Neutral));
public static readonly VoteDirection DownVote = new VoteDirection(2, nameof(DownVote));
public static readonly VoteDirection UpVote = new VoteDirection(3, nameof(UpVote));
/// <inheritdoc />
private VoteDirection(
int id,
string name)
: base(id, name)
{
}
} Edit: I was just thinking that this would also be a very cool |
I don't understand the relationship between the enum and the error. From a domain perspective, the values are 'Neutral', 'DownVote' & 'UpVote', so what role does values 1,2 & 3 have? If it is to save on storage, the translation will be in the DTO. |
I've been searching for a bit, and am wondering if you had a moment to post that blog post. The only documentation I can find on this class (other than the code) is:
Thanks!
My implementation of
EnumValueObject
I would like to use it to represent 'votes'.For example, let's look at the votes on Reddit
Yourself as a user can perform these voting actions on a post:
I have an application in which I have 'comments', and I would like to add this feature.
I would like the
ValueObjectEnum
values to be something like:It could even be:
The numbers are an
int
and represent an index. I saw in the code that it only allows forstring
.Is there any way I can use an
int
instead of astring
?If not, would you be open to a PR which brought the feature over from SmartEnum
Or possibly even the best solution, allow for a dependency (or optional dependency in a separate NuGet package of SmartEnum
Originally posted by @jeffward01 in #255 (comment)
The text was updated successfully, but these errors were encountered: