public bool TryGetProperty(UserAccountProperties property, out object returnObject) { returnObject = null; if (mUserPropertiesDictionary.TryGetValue(property, out returnObject)) { return(true); } return(false); }
public bool SetAccountProperty <T>(UserAccountProperties userAccountProperty, T value) { try { mUserProperties.SetProperty(userAccountProperty, value); SaveUserProperties(); return(true); } catch (System.Exception) { return(false); } }
public bool TryGetAccountProperty <T>(UserAccountProperties userAccountProperty, ref T returnObject) { object findObjectInDictionary = null; if (mUserProperties.TryGetProperty(userAccountProperty, out findObjectInDictionary)) { try { returnObject = (T)findObjectInDictionary; return(true); } catch (System.Exception ex) { throw ex; } } return(false); }
private Dictionary <UserAccountProperties, object> StringToUserPropertyDictionary(string xmlDocumentString) { Dictionary <UserAccountProperties, object> userPropertyDictionary = new Dictionary <UserAccountProperties, object>(); XmlDocument deserializedXmlDocument = new XmlDocument(); try { deserializedXmlDocument.LoadXml(xmlDocumentString); } catch (System.Exception ex) { throw new System.Exception("Error converting string to xml: >" + xmlDocumentString + "<\n" , ex); } XmlNode userPropertiesXmlNode = deserializedXmlDocument.SelectSingleNode(ConstStrings.kUserProperties); if (userPropertiesXmlNode != null) { XmlNodeList userPropertyXmlNodeList = userPropertiesXmlNode.SelectNodes(ConstStrings.kUserProperty); foreach (XmlNode userPropertyXmlNode in userPropertyXmlNodeList) { string nameString = string.Empty; string typeString = string.Empty; string valueString = string.Empty; if ((XmlUtil.TryGetAttributeFromXml(ConstStrings.kName, userPropertyXmlNode, out nameString) && XmlUtil.TryGetAttributeFromXml(ConstStrings.kType, userPropertyXmlNode, out typeString) && XmlUtil.TryGetAttributeFromXml(ConstStrings.kValue, userPropertyXmlNode, out valueString))) { try { //try and convert the string name to the UserAccountProperties enum UserAccountProperties userAccountProperty = (UserAccountProperties)Enum.Parse(typeof(UserAccountProperties), nameString, false); Type typeValue = Type.GetType(typeString); object objectValue = null; try { objectValue = Convert.ChangeType(valueString, typeValue); } catch (System.Exception) { try { //look for a constructor on our type that takes a string as a parameter System.Reflection.ConstructorInfo typeConstructorInfo = typeValue.GetConstructor(new Type[1] { typeof(string) }); //call that constructor with our valueString objectValue = typeConstructorInfo.Invoke(new object[1] { valueString }); } catch (System.Exception exInner) { throw new System.Exception("Cannot cast from string to type: " + typeValue.Name + ". Does this type implement a explicit cast operator from a string?", exInner); } } userPropertyDictionary.Add(userAccountProperty, objectValue); } catch (System.Exception) { continue; } } else { continue; } } } return(userPropertyDictionary); }
public void SetProperty(UserAccountProperties property, object propertyValue) { mUserPropertiesDictionary[property] = propertyValue; }
public bool TryGetProperty(UserAccountProperties property) { return(mUserPropertiesDictionary.ContainsKey(property)); }