There is a class with messages for UI. I would like to give each message a unique number without manually writing it in the code. These numbers can then be used in tests. So far, it has been done like this:
public class UserMessage { private static int _index = 0; private UserMessage(string message) { this.Code = System.Threading.Interlocked.Increment(ref _index); this.Message = message; } public int Code { get; private set; } public string Message { get; private set; } public static class Group1 { public static readonly UserMessage msg1 = new UserMessage("msg1"); // ... } public static class Group2 { public static readonly UserMessage msg2 = new UserMessage("msg2"); // ... } } The problem is that the order of calling static constructors is not defined, and if the code is executed on different IIS servers, messages may receive different codes. Is it possible to guarantee the same numbering at run time?
The ultimate goal is to get the same numbering each time the code is executed.