Exemplo n.º 1
0
        public static object Value(this object objValue, Type type)
        {
            TkDebug.AssertArgumentNull(type, "type", null);

            if (objValue == null || objValue == DBNull.Value)
            {
                return(ObjectUtil.GetTypeDefaultValue(type));
            }
            if (objValue.GetType() == type)
            {
                return(objValue);
            }
            try
            {
                return(System.Convert.ChangeType(objValue, type, ObjectUtil.SysCulture));
            }
            catch
            {
                return(ObjectUtil.GetDefaultValue(objValue.ToString(), type));
            }
        }