Thursday, 15 September 2011

String References in C# -


This is my first post.

I am selecting some fields from a database that have numerical ID values ​​such as 10,20,100,110 etc. These numbers are actually something meaningful as the area. Ideally there should be a database table with the database ID and name field, but it is not so and it is now difficult to implement it in the appropriate time frame (politics).

I currently check to use a bad switch function id and relat text back.

Private string GetUnitName (string field) {string areaName = string.Empty; Switch (areaid.Trim ()) {case "10": area name = "area 1"; break; Case "20": Area Name = "Area 2"; break; Case "30": Area name = "Region 3"; break; } Return field name; }

I can not take them at any date time, so what is the best way to store the stars in this area?
Can I group them in a setting file or something?

As an enum, you have to compile again if you ever They need to change (depending on how often they change)?

Alternatively, you may have an XML document that you can hide in the cache and expo to find the text for the ID?

  & lt; Areas & gt; & Lt; Field id = "10" & gt; Region 1 & lt; / Region & gt; & Lt; Field id = "20" & gt; Region 2 & lt; / Region & gt; & Lt; Field id = "30" & gt; Area 3 & lt; / Region & gt; & Lt; / Regions & gt; XPath: / regions / region [@id = '& lt; Your ID is here>]]  

If the file has changed then set to end the cache dependency, when you update it, you will not restart anything To speed up, you can read it as a hash in memory so that you do not have to keep XPathing all the time at the doctor.


No comments:

Post a Comment