Beispiel #1
0
        /// <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 = AVClient.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);
        }
Beispiel #2
0
 /// <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
 /// AVObject and its descendents, LeanCloud types such as AVRelation and AVGeopoint,
 /// primitive types,IList&lt;T&gt;, IDictionary&lt;string, T&gt; 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)AVClient.ConvertTo <T>(this.properties[key]));
 }