public T GetProperty <T>(string pPropName) { T ret = default(T); lock (Properties) { if (Properties.TryGetValue(pPropName, out PropertyDefnBase pbase)) { if (pbase.type == typeof(T)) { PropertyDefn <T> defn = pbase as PropertyDefn <T>; if (defn != null && defn.getter != null) { ret = defn.getter(); } } else { // The caller is asking for a different type than the native type. // Get the value and try to do a conversion to the requested type. // Probably wants to do a ToString(). try { ret = ParamBlock.ConvertTo <T>(pbase.val); } catch (Exception e) { BasilXContext.Instance.log.ErrorFormat("{0} GetProperty: exception fetching value for {1}: {2}", _logHeader, pPropName, e); ret = default(T); } } } } return(ret); }
// Set a property value public void SetProperty <T>(string pPropId, T value) { lock (Properties) { if (Properties.TryGetValue(pPropId, out PropertyDefnBase pbase)) { if (pbase.type == typeof(T)) { PropertyDefn <T> defn = pbase as PropertyDefn <T>; if (defn.setter != null) { defn.setter(value); } } } } }
public void DefineProperty <T>(string pProp, PropertyDefn <T> pDefn) { lock (Properties) { Properties.Add(pProp, pDefn); } }