Friday 15 July 2011

casting - c# store different settings in one object -


I have an object that shows the current event that is happening. There are many settings in this event, what is the best practice to store all setting variables within the event object?

The settings have been stored in the database (currently in different columns depending on base class: value string, value point, value, validity time, value float, pricing).

As soon as I loaded the event object, I will store it in the local cache for quick access.

Do I object to everything? (Feel uncomfortable to get / set settings)

  class event {// string = settings key dictionary & lt; String, Object & gt; _Settings; Public Zero AddSetting (String Key, Object Value) Public Object GetSetting (String Key)}   

Should I be in different dictionaries?

  class event {// string = settings key dictionary & lt; String, string & gt; _settingStrings; Dictionary & lt; String, int & gt; _settingInts; Public Zero AddSetting (String Key, String Value) Public Zero AddSetting (String Key, Int Value) ... Public String GetStringSetting (String Key) Public Int GetIntSetting (String Key) ...}   

Any thoughts?

You can store everything as Object

  Private ID Works & lt; String, Object & gt; _settings = New Dictionary & lt; String, Object & gt; (); Public Zero AddSetting & lt; T & gt; (String key, t value) {_settings [key] = value; } PublicT GetSetting & lt; T & gt; (String key, not t = default (t)) {object res; If (! _ Settings, tregate value (key, out ridge) ||! (Resolution is t)) {not return; } Return (t) race; }   

The cast remains there, but the API hides it from the user: now the user safely

  string search path = setting the container.gate setting & Lt; String & gt; ("SearchPath"); Int retryCount = settingContainer.GetSetting & lt; Int & gt; ("RetryCount", -1);    

No comments:

Post a Comment