/// <summary> /// Populates result with the value for the key, if possible. /// </summary> /// <typeparam name="T">The desired type for the value.</typeparam> /// <param name="key">The key to retrieve a value for.</param> /// <param name="result">The value for the given key, converted to the /// requested type, or null if unsuccessful.</param> /// <returns>true if the lookup and conversion succeeded, otherwise false.</returns> public bool TryGetValue <T>(string key, out T result) { if (this.properties.ContainsKey(key)) { var temp = ParseClient.ConvertTo <T>(this.properties[key]); if (temp is T || (temp == null && (!typeof(T).GetTypeInfo().IsValueType || typeof(T).IsNullable())) ) { result = (T)temp; return(true); } } result = default(T); return(false); }
/// <summary> /// Gets a value for the key of a particular type. /// </summary> /// <typeparam name="T">The type to convert the value to. Supported types are /// ParseObject and its descendents, Parse types such as ParseRelation and ParseGeopoint, /// primitive types,IList<T>, IDictionary<string, T> and strings.</typeparam> /// <param name="key">The key of the element to get.</param> /// <exception cref="System.Collections.Generic.KeyNotFoundException">The property is retrieved /// and <paramref name="key"/> is not found.</exception> /// <exception cref="System.FormatException">The property under this <paramref name="key"/> /// key was found, but of a different type.</exception> public T Get <T>(string key) { return((T)ParseClient.ConvertTo <T>(this.properties[key])); }