I'm a professional php programmer and lately I started a project in C#. These are my first steps with C#.
For one of my solutions I would like to use global CONSTs. I'm aware that C# doesn't allow you to define any variable outside a class scope, but I would like to try and implement something like it anyway, even just for the purpose of learning different techniques in the language.
I see the best way to do something similar global CONSTs is to define a static class, let's call it Const, that will hold my all of my solution's 'constants'. The class will use a private dictionary to hold the values, a method called 'define()' to set a value in this dictionar, 'is_defined()' to check if a const exists etc..
Now I'm about to write the method that will return the value. Obviously I could use a method Const.GetConst('someConstName') and get the wanted value, but that's a long way to retrieve a const anytime I need it. I though of using something like PHP's magic getter (if you're not familiar with it - you define inside a class a method called '__get' which handles all requests for a variable inside the class which is not defined). However, I couldn't find anything similar in C#. The closest thing I could find is a way to dynamically create a method inside a class in runtime, so that everytime a CONST will be created in my class, I'll create a "get method" that will pull the value from the private dictionary (this is not a get method in the classic form because is won't return a variable, instead, it will look for a value in a dictionary and return it).
Basically, what I'm asking is - - Is there any way to define global consts? - (even id the answer to the previous question is yes) Is there a way to set a better getter for dynamically define variables?
Thank you very much for the help