String enums - current consensus
Hi!
What is the current consensus on string enum
Any special library,
Some abstract class that defines helper methods with attributes etc.
Example usage:
13 Replies
afaik enums are numbers
I understand that
My point is how does one go about implementing custom string enums in c#
What is the currently agreed upon standard
technically you could do
some Enumeration abstract class like so
some library handling it in compiletime
etc.
there are many ways to go on about it, which is currently proposed to be the best one
Arent Enumerations things you loop over?
you're talking about Enumerables
most go for static readonly strings
the point is I later deserialize them in dapper into values to use in queries
why not use that fancy EF Core stuff
i heard its bad practice to write raw SQL queries but i have no idea abt that stuff yet so :stare:
Different people, different needs
Some people need fine-grained queries for their needs
It can be better for optimization and suiting one's specific needs without fighting with EFCore
If you need something similar to enum just with strings then you could do the following:
I apologize however I do not believe we understand each other, as I have already mentioned this solution
and have also explained my usage and why it might not necessarily work with my current setup
I'll try Intellenum for now, but I am open to suggestions
for reference:
https://github.com/andrewlock/NetEscapades.EnumGenerators
and use
.ToStringFast()
instead of .ToString()
Thank you! Looks nice
Quick question though,
Do you happen to know if there is a way to add a dapper anonymous parameter converter to it so I do not have to map these enums into values before sending them in a query?
Nevermind! Found it!
https://andydote.co.uk/2014/07/22/configuring-dapper-to-work-with-custom-types/
I can do reflectionbased setup during initialization of the server
https://andydote.co.uk/2014/07/22/configuring-dapper-to-work-with-custom-types/
Configuring Dapper to work with custom types
In the last post we looked at using custom ID types to help abstract the column type from the domain.
This works well until you start trying to load and save entities using an ORM, as the ORM has not way to know how to map a column to a custom type. ORMs provide extension points to allow you to create these mappings. As I tend to favour using Da...