private static object GetPropertyValue(VersionedSchemaObjectBase obj, SchemaPropertyDefine pd) { try { object defaultValue = TypeCreator.GetTypeDefaultValue(pd.DataType.ToRealType()); object result = defaultValue; if (pd.DataType == PropertyDataType.Enum) { result = obj.Properties.GetValue(pd.Name, (object)null); } else { result = obj.Properties.GetValue(pd.Name, defaultValue); } return(result); } catch (System.Exception ex) { throw new SystemSupportException(string.Format("生成Snapshot或全文检索时,{0}属性值获取错误: {1}", pd.Name, ex.Message), ex); } }
private static object GetPropertyValue(SchemaObjectBase obj, SchemaPropertyDefine pd) { try { object defaultValue = TypeCreator.GetTypeDefaultValue(pd.DataType.ToRealType()); return(obj.Properties.GetValue(pd.Name, defaultValue)); } catch (System.Exception ex) { throw new SystemSupportException(string.Format("生成Snapshot或全文检索时,{0}属性值获取错误: {1}", pd.Name, ex.Message), ex); } }
private static string InitDefaultValue(ClientPropertyDataType dataType, string defaultValue) { string result = defaultValue; if (defaultValue.IsNullOrEmpty() && dataType != ClientPropertyDataType.String) { object data = TypeCreator.GetTypeDefaultValue(dataType.ToRealType()); if (data != null) result = data.ToString(); } return result; }
private static bool IsTypeDefaultValue(ConditionMappingItemBase item, object data) { bool result = false; if (data != null) { Type type = GetMemberInfoType(item.MemberInfo); if (type == typeof(object)) { type = data.GetType(); } if (type.IsEnum) { result = false; if (type == typeof(BooleanState)) { result = ((BooleanState)data) == BooleanState.Unknown; } else { result = data.Equals((int)TypeCreator.GetTypeDefaultValue(type)); } } else { if (type == typeof(string)) { result = string.IsNullOrEmpty((string)data); } else { result = data.Equals(TypeCreator.GetTypeDefaultValue(type)); } } } else { result = true; } return(result); }
private static void DoInsertUpdateSqlClauseBuilder <T>(SqlClauseBuilderIUW builder, DataProperty property, T graph) { object data = GetPropertyValue(property, graph); if (data == null || data == DBNull.Value || data.Equals(TypeCreator.GetTypeDefaultValue(data.GetType()))) { if (string.IsNullOrWhiteSpace(property.DefaultValue)) { data = DBNull.Value; } else { builder.AppendItem(property.FieldName, property.DefaultValue, SqlClauseBuilderBase.EqualTo, true); } } else { builder.AppendItem(property.FieldName, data); } }
private static IDictionary <string, object> LoadExtDataFromRawExtData(string raw) { IDictionary <string, object> result = new Dictionary <string, object>(); if (string.IsNullOrEmpty(raw) == false) { XmlDocument xmlDoc = XmlHelper.CreateDomDocument(raw); foreach (XmlNode elem in xmlDoc.DocumentElement) { string typeDesc = XmlHelper.GetAttributeValue(elem, "type", "System.String"); object defaultValue = TypeCreator.GetTypeDefaultValue(TypeCreator.GetTypeInfo(typeDesc)); result.Add(XmlHelper.GetAttributeText(elem, "key"), XmlHelper.GetAttributeValue(elem, "value", defaultValue)); } } return(result); }
private static void DoInsertUpdateSqlClauseBuilder <T>(SqlClauseBuilderIUW builder, ORMappingItem item, T graph) { if (item.IsIdentity == false) { object data = GetValueFromObject(item, graph); if ((data == null || data == DBNull.Value || (data != null && data.Equals(TypeCreator.GetTypeDefaultValue(data.GetType())))) && string.IsNullOrEmpty(item.DefaultExpression) == false) { builder.AppendItem(item.DataFieldName, item.DefaultExpression, SqlClauseBuilderBase.EqualTo, true); } else { builder.AppendItem(item.DataFieldName, data); } } }
/// <summary> /// 判断该映射字段对应的属性 的值是否是类型默认值 /// </summary> /// <param name="condtion"></param> /// <param name="item"></param> /// <param name="data"></param> /// <returns></returns> private static bool IsTypeDefaultValue(this object condtion, ConditionMappingItem item, out object data) { data = null; var pi = item.MemberInfo as PropertyInfo; if (pi == null) { return(true); } if (pi.CanRead == false) { return(true); } data = pi.GetValue(condtion, null); if (data == null) { return(true); } Type type = pi.PropertyType; if (type == typeof(object)) { type = data.GetType(); } else if (type.IsEnum) { int d = (int)data; data = d.ToString(); if (d > 0) { return(false); } return(true); } else if (type == typeof(DateTime)) { DateTime dt = (DateTime)data; if (dt == DateTime.MinValue) { return(true); } return(false); } else if (type == typeof(decimal)) { decimal dci = (decimal)data; if (dci == decimal.MinValue) { return(true); } return(false); } else if (type == typeof(int)) { int intd = (int)data; if (intd == int.MinValue) { return(true); } return(false); } else if (type == typeof(string)) { return(string.IsNullOrEmpty((string)data)); } return(data.Equals(TypeCreator.GetTypeDefaultValue(type))); }
private static void DoSelectSqlClauseBuilder <TBuilder, T>(TBuilder builder, ORMappingItem item, T graph) where TBuilder : SqlClauseBuilderIUW <TBuilder> { if (item.PrimaryKey == false) { object data = GetValueFromObject(item, graph); if ((data == null || data == DBNull.Value || (data != null && data.Equals(TypeCreator.GetTypeDefaultValue(data.GetType()))))) { if (item.DefaultExpression.IsNullOrEmpty()) { builder.AppendItem(item.DataFieldName, "NULL", ""); } else { builder.AppendItem(item.DataFieldName, item.DefaultExpression, "", true); } } else { builder.AppendItem(item.DataFieldName, FormatValue(data, item)); } } }
private static void DoInsertUpdateSqlClauseBuilder <TBuilder, T>(TBuilder builder, ORMappingItem item, T graph) where TBuilder : SqlClauseBuilderIUW <TBuilder> { if (item.IsIdentity == false) { object data = GetValueFromObject(item, graph); bool considerNull = data == null || data == DBNull.Value || (data != null && data.Equals(TypeCreator.GetTypeDefaultValue(data.GetType()))); if ((item.ForceUseDefaultExpression || considerNull) && item.DefaultExpression.IsNotEmpty()) { builder.AppendItem(item.DataFieldName, item.DefaultExpression, SqlClauseBuilderBase.EqualTo, true); } else { builder.AppendItem(item.DataFieldName, FormatValue(data, item)); } } }