xxyy
2025-03-10 457b75b642a1fdaa7158e5b047cabc5d7ae16333
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_Core/Utilities/EntityProperties.cs
@@ -58,7 +58,6 @@
            }
            else if (dbType == SqlDbTypeName.Float || dbType == SqlDbTypeName.Decimal || dbType == SqlDbTypeName.Double)
            {
                if (!val.IsNumber(null))
                {
                    reslutMsg = "不是有效数字";
@@ -78,7 +77,6 @@
                || dbType == SqlDbTypeName.Char
                || dbType == SqlDbTypeName.Text))
            {
                //默认nvarchar(max) 、text 长度不能超过20000
                if (val.Length > 200000)
                {
@@ -86,7 +84,6 @@
                }
                else
                {
                    int length = sugarColumn.Length;
                    if (length == 0) { return (true, null, null); }
                    //判断双字节与单字段
@@ -118,6 +115,7 @@
            {  typeof(byte),SqlDbTypeName.Int },//类型待完
            { typeof(Guid),SqlDbTypeName.UniqueIdentifier}
        };
        public static string GetProperWithDbType(this PropertyInfo propertyInfo)
        {
            bool result = ProperWithDbType.TryGetValue(propertyInfo.PropertyType, out string value);
@@ -189,12 +187,28 @@
                    }
                    continue;
                }
                string str = dic[property.Name.FirstLetterToLower()].ToString();
                string str = dic.GetValueOrDefault(property.Name.FirstLetterToLower(), "").ToString();
                //将所有空值设置为null
                if (dic[property.Name.FirstLetterToLower()] != null && str == string.Empty)
                    dic[property.Name.FirstLetterToLower()] = null;
            }
            return string.Empty;
        }
        /// <summary>
        /// 安全获取字典值,如果键不存在或值为null则返回默认值
        /// </summary>
        /// <typeparam name="TKey">字典键的类型</typeparam>
        /// <typeparam name="TValue">字典值的类型</typeparam>
        /// <param name="dictionary">字典实例</param>
        /// <param name="key">键</param>
        /// <param name="defaultValue">默认值</param>
        /// <returns>字典值或默认值</returns>
        public static TValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue defaultValue = default)
        {
            if (dictionary == null) throw new ArgumentNullException(nameof(dictionary));
            return dictionary.TryGetValue(key, out TValue value) && value != null ? value : defaultValue;
        }
        public static string GetKeyName(this Type typeinfo)
@@ -294,4 +308,4 @@
            return null;
        }
    }
}
}