public static void SetValue(this IDbDataParameter dbParameter, object value, Type type)
 {
     if (value == null)
     {
         if (type.IsNullable())
         {
             dbParameter.Value = TypeConvert.GetDefault(type.GetNullableType());
         }
         else if (type.IsValueType)
         {
             dbParameter.Value = TypeConvert.GetDefault(type);
         }
         else
         {
             DbType?dbType = GetDbType(type);
             if (dbType.HasValue)
             {
                 dbParameter.DbType = dbType.Value;
             }
         }
         dbParameter.Value = DBNull.Value;
     }
     else
     {
         dbParameter.Value = value;
     }
 }
Exemple #2
0
        /// <summary>
        /// Determines if a property is different from its default value
        /// </summary>
        /// <param name="target"></param>
        /// <param name="memberInfo"></param>
        /// <returns></returns>
        protected virtual bool IsSpecified(object target, MemberInfo memberInfo)
        {
            object value = memberInfo.GetMemberValue(target);

            if (value == null)
            {
                return(false);
            }
            if (Equals(value, TypeConvert.GetDefault(memberInfo.GetMemberType())))
            {
                return(false);
            }
            return(true);
        }
 /// <summary>
 /// Returns default value for provided type
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public static object GetDefault(this Type t)
 {
     return(TypeConvert.GetDefault(t));
 }