I have to implement a solution something like - my c# function I use so many harcoded five digits codes. what I want to so is to move these hard coded values into a mapping config file(some xml) and The config will map the codes to constants that can be used in my function.
This will help to update the code value without source code re-compilation.
XML would be like:
<Codes>
<Code>
<key>code_name_1</key>
<value>value_1</value>
</Code>
...
</Codes>
OR
<Codes>
<Code key='code_name_1' value='value_1'>
<Code key='code_name_2' value='value_2'>
<Code key='code_name_3' value='value_3'>
...
</Codes>
mapping class would be:
static class codeMapping
{
const sting code1 = "code_name_1";
const sting code2 = "code_name_2";
const sting code3 = "code_name_3";
const sting code4 = "code_name_4";
...
}
function where I want to get these values:
class someClass
{
...someFunction(string someCode)
{
...
if(someCode == codeMapping.code1)
...do something
var temp2 = codeMapping.code2;
...
}
}
How to initialize constant variables of codeMapping class to the corresponding config valies? Any better design concept is also accepted.