Eeee is the risk of karma ...
I have a DRY absorbed unit of measure, because, since there are too many query variables to continue the inheritance conversion,
Below is the utility code, the constructor of which requires the input of NameValueCollection (this.source) and the "keys" of the string array, because the legacy application was quite organic and developed the ability for several different strings to be a potential input key. However, I kind of like extensibility. This method checks the collection for the key and returns it in the required data type.
private T GetValue<T>(string[] keys) { return GetValue<T>(keys, default(T)); } private T GetValue<T>(string[] keys, T vDefault) { T x = vDefault; string v = null; for (int i = 0; i < keys.Length && String.IsNullOrEmpty(v); i++) { v = this.source[keys[i]]; } if (!String.IsNullOrEmpty(v)) { try { x = (typeof(T).IsSubclassOf(typeof(Enum))) ? (T)Enum.Parse(typeof(T), v) : (T)Convert.ChangeType(v, typeof(T)); } catch(Exception e) {
annakata Dec 08 '08 at 14:54 2008-12-08 14:54
source share