Ejemplo n.º 1
0
        /// <summary>
        /// Try to cast property to given type.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="property">The property name.</param>
        /// <param name="value">The value.</param>
        /// <returns>True if value is found and converted.</returns>
        public bool TryGet <T>(String property, out T value)
        {
            try
            {
                object v;
                if (TryGetValue(property, out v) && v != null)
                {
                    if (v is string)
                    {
                        value = (T)DextopUtil.DecodeValue(v as string, typeof(T));
                    }
                    else
                    {
                        value = (T)Codaxy.Common.Convert.ChangeType(v, typeof(T));
                    }
                    return(true);
                }
            }
            catch {}

            value = default(T);
            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Try to cast property to given type.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="property">The property name.</param>
        /// <param name="value">The value.</param>
        /// <returns>True if value is found and converted.</returns>
        public bool TryConvert(String property, out object value, Type type)
        {
            try
            {
                object v;
                if (TryGetValue(property, out v) && v != null)
                {
                    if (v is string)
                    {
                        value = DextopUtil.DecodeValue(v as string, type);
                    }
                    else
                    {
                        value = Codaxy.Common.Convert.ChangeType(v, type);
                    }
                    return(true);
                }
            }
            catch { }

            value = null;
            return(false);
        }