I am developing my own identity system for my ASP.Net 5 application, and I am currently looking for an efficient way to store my predefined error codes and their corresponding descriptions. Does anyone have any suggestions to my issue?
Asked
Active
Viewed 49 times
-1
-
How are these 'error codes' to be used? Anyway .. I would probably start with an enum and [put the description in attributes](http://stackoverflow.com/questions/1799370/getting-attributes-of-enums-value). This is because the error codes [probably] are *a fixed set* that are intrinsically part of the code itself, with the description coming along for the ride. Resolving the enum value to description would be tucked away in some DI-Service so that even if the descriptions were resolved via not-attributes later there would be no code change at the usage sites. – user2864740 Jul 03 '15 at 05:14
-
Well an error code is represented as a string; for example, "PasswordInvalid". – Alex Justi Jul 03 '15 at 05:19
-
1An enum represents values. The string represents a value (where each 'error code string' would represent a specific error). Then consider the trivial mapping: `enum ErrorCode { PasswordInvalid, AccountLocked }`. Anyway, do you really use the *string* to represent the error code? And if so, *why*? – user2864740 Jul 03 '15 at 05:20
-
1Relevant if using a enum: http://stackoverflow.com/questions/4367723/get-enum-from-description-attribute – user2864740 Jul 03 '15 at 05:46
1 Answers
2
Use resource files: https://msdn.microsoft.com/en-us/library/windows/desktop/aa380599%28v=vs.85%29.aspx
They allow you to store the name of the error code, the error code and a description. Then use Properties.Resources to access them.

Jansky
- 1,455
- 1
- 17
- 33