public EntityProperty(string Name, string Desc, EntityPropertyType Type) : this() { name = Name; description = Desc; type = Type; }
/// <summary> /// 字段 /// </summary> /// <param name="paramName">字段名</param> /// <param name="dbType">数据库类型</param> /// <param name="allowNull">允许空</param> /// <param name="type">类型</param> /// <param name="length">长度</param> /// <returns></returns> public KeyWordTableParamItem Param(string paramName, DbType dbType, bool allowNull, EntityPropertyType type, int length) { KeyWordTableParamItem item = new KeyWordTableParamItem(_tableName, this); return(item._(paramName, dbType, allowNull, type, length)); }
public static object FromString(EntityPropertyType type, string value) { if (type == EntityPropertyType.String) return value; #if !(RELEASE && RELEASE_DISABLE_CHECKS) if (value == null) throw new System.ArgumentNullException("value"); if (value.Length < 1) throw new System.ArgumentException("value string was empty"); #endif switch (type) { case EntityPropertyType.Bool: { if (value == "0") value = "false"; else if (value == "1") value = "true"; return bool.Parse(value); } case EntityPropertyType.Int: return int.Parse(value); case EntityPropertyType.Float: return float.Parse(value); case EntityPropertyType.Vec3: return Vec3.Parse(value); } return null; }
private void ProcessPropertyValue(XmlReader reader) { if (state != ParserState.Property) { throw new InvalidOperationException("Not expecting element content for state " + state); } StackFrame topFrame = stack.Peek(); Type targetType = topFrame.entity.Properties[topFrame.elementName].Type; EntityPropertyType itemType = topFrame.entity.Properties[topFrame.elementName].EntityPropertyType; if (!topFrame.dynamic && topFrame.property != null) { topFrame.property.SetValue(topFrame.instance, DeserializeScalarValue(reader.Value, itemType, targetType), null); } else { if (hasAddMethod) { topFrame.iAddInstance.SetPropertyValue(topFrame.elementName, DeserializeScalarValue(reader.Value, itemType, targetType)); } else { topFrame.addMethod.Invoke(topFrame.instance, new[] { topFrame.elementName, DeserializeScalarValue(reader.Value, itemType, targetType) }); } } }
/// <summary> /// Initializes a new <see cref="EntityProperty"/>. /// </summary> /// <param name="conceptualModel">The model a property belongs to.</param> /// <param name="element">The backing property element.</param> /// <param name="name">The property name.</param> /// <param name="type">The property type.</param> public EntityProperty(INamespacedOperations conceptualModel, XElement element, string name, EntityPropertyType type) { _conceptualModel = conceptualModel ?? throw new ArgumentNullException(nameof(conceptualModel)); _element = element; Name = name; Type = type; }
private object DeserializeScalarValue(string value, EntityPropertyType columnType, Type targetType) { switch (columnType) { case EntityPropertyType.Boolean: case EntityPropertyType.Byte: case EntityPropertyType.Char: case EntityPropertyType.Decimal: case EntityPropertyType.Double: case EntityPropertyType.Int16: case EntityPropertyType.Int32: case EntityPropertyType.Int64: case EntityPropertyType.Single: case EntityPropertyType.String: case EntityPropertyType.Type: case EntityPropertyType.Uri: return(Convert.ChangeType(value, targetType, CultureInfo.InvariantCulture)); case EntityPropertyType.Blob: return(Convert.FromBase64String(value)); case EntityPropertyType.Guid: return(new Guid(value)); case EntityPropertyType.DateTime: return(DateTime.Parse(value, CultureInfo.InvariantCulture)); case EntityPropertyType.Null: return(null); default: throw new InvalidOperationException(string.Format("Unsupported property type {0}", columnType)); } }
/// <summary> /// 字段 /// </summary> /// <param name="paramName">字段名</param> /// <param name="dbType">数据库类型</param> /// <param name="allowNull">允许空</param> /// <param name="type">类型</param> /// <param name="length">长度</param> /// <returns></returns> public KeyWordAddParamItem AddParam(string paramName, DbType dbType, bool allowNull, EntityPropertyType type, int length) { EntityParam info = new EntityParam("", paramName, "", dbType, type, "", length, false, false); KeyWordAddParamItem item = new KeyWordAddParamItem(info, _tableName, this); return(item); }
/// <summary> /// 添加字段 /// </summary> /// <param name="paramName">字段名</param> /// <param name="dbType">数据库类型</param> /// <param name="allowNull">允许空</param> /// <param name="type">类型</param> /// <param name="length">长度</param> /// <returns></returns> public KeyWordTableParamItem _(string paramName, DbType dbType, bool allowNull, EntityPropertyType type, int length) { EntityParam info = new EntityParam("", paramName, "", dbType, type, "", length, false, false); _tparams.Add(info); return(this); }
/// <summary> /// 填充字段信息 /// </summary> /// <param name="prm">字段信息</param> /// <param name="reader">reader</param> private void FillParam(DBTableInfo table, DataRow row, Dictionary <string, bool> dicPk, DataTable dtData) { string prmName = row["COLUMN_NAME"] as string; if (string.IsNullOrEmpty(prmName)) { return; } foreach (EntityParam ep in table.Params) { if (ep.ParamName == prmName) { return; } } EntityParam prm = new EntityParam(); prm.ParamName = prmName; EntityPropertyType type = EntityPropertyType.Normal; string key = table.Name + ":" + prmName; key = key.ToLower(); bool isPrimary = dicPk.ContainsKey(key); bool isIdentity = IsIdentity(dtData, prmName); if (isPrimary) { type = EntityPropertyType.PrimaryKey; } if (isIdentity) { type = type | EntityPropertyType.Identity; } prm.AllowNull = Convert.ToBoolean(row["IS_NULLABLE"]); prm.PropertyType = type; if (!row.IsNull("CHARACTER_MAXIMUM_LENGTH")) { prm.Length = Convert.ToInt64(row["CHARACTER_MAXIMUM_LENGTH"]); } if (!table.IsView) { prm.Description = row["DESCRIPTION"] as string; } int dbType = 0; if (!row.IsNull("DATA_TYPE")) { dbType = Convert.ToInt32(row["DATA_TYPE"]); } prm.SqlType = GetDbType(dbType); table.Params.Add(prm); }
/// <summary> /// Ctor /// </summary> /// <param name="type">Either a value type, a reference type, or a reference list.</param> /// <param name="column">The column mapped to this property. Can be null.</param> public EntityPropertyAttribute(EntityPropertyType type, string column) { Type = type; if (column == null) { ColumnName = string.Empty; } ColumnName = column; }
/// <summary> /// 填充字段信息 /// </summary> /// <param name="prm">字段信息</param> /// <param name="reader">reader</param> private void FillParam(DBTableInfo table, IDataReader reader, Dictionary <string, bool> pkNames) { string prmName = reader["COLUMN_NAME"] as string; if (string.IsNullOrEmpty(prmName)) { return; } foreach (EntityParam ep in table.Params) { if (ep.ParamName == prmName) { return; } } EntityParam prm = new EntityParam(); prm.ParamName = prmName; EntityPropertyType type = EntityPropertyType.Normal; int isIdentity = 0; if (pkNames.ContainsKey(prmName)) { type = EntityPropertyType.PrimaryKey; //isIdentity = 1; } //if (isIdentity == 1) //{ // type = type | EntityPropertyType.Identity; //} prm.PropertyType = type; prm.Length = Convert.ToInt64(reader["DATA_LENGTH"]); if (!table.IsView) { prm.Description = reader["COMMENTS"] as string; } object val = reader["NULLABLE"]; bool isNull = false; if (!(val is DBNull)) { isNull = val.ToString().Equals("Y", StringComparison.CurrentCultureIgnoreCase); } prm.AllowNull = isNull; string strDBType = reader["DATA_TYPE"] as string; prm.SqlType = GetDbType(strDBType); table.Params.Add(prm); }
private object DeserializeScalarValue(string value, EntityPropertyType columnType, Type targetType, ColumnInfo currentColumn) { switch (columnType) { case EntityPropertyType.String: if (currentColumnEncoded) { if (DBBase64.Equals(currentColumnEncodingType, StringComparison.OrdinalIgnoreCase)) { value = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(value)); } } return(Convert.ChangeType(value, targetType, CultureInfo.InvariantCulture)); case EntityPropertyType.Boolean: case EntityPropertyType.Byte: case EntityPropertyType.Char: case EntityPropertyType.Decimal: case EntityPropertyType.Double: case EntityPropertyType.Int16: case EntityPropertyType.Int32: case EntityPropertyType.Int64: case EntityPropertyType.Single: case EntityPropertyType.Type: case EntityPropertyType.Uri: return(Convert.ChangeType(value, targetType, CultureInfo.InvariantCulture)); case EntityPropertyType.Blob: return(Convert.FromBase64String(value)); case EntityPropertyType.Guid: return(new Guid(value)); case EntityPropertyType.DateTime: if (currentColumn.DateTimeMode.HasValue) { if (currentColumn.DateTimeMode.Value == DataSetDateTime.Local) { return(DateTime.ParseExact(value, "o", CultureInfo.InvariantCulture)); } else if (currentColumn.DateTimeMode.Value == DataSetDateTime.Utc) { return(DateTime.ParseExact(value, "o", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal)); } } return(DateTime.ParseExact(value, "o", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind)); case EntityPropertyType.Null: return(value); default: throw new InvalidOperationException(string.Format("Unsupported property type {0}", columnType)); } }
private void ProcessArrayPropertyItem(XmlReader reader) { StackFrame topFrame = stack.Peek(); EntityPropertyType itemType = topFrame.entity.Properties[topFrame.elementName].EntityPropertyType; Type targetType = topFrame.entity.Properties[topFrame.elementName].Type.GetElementType(); object value = DeserializeScalarValue(reader.Value, itemType, targetType); arrayItems.Add(value); }
/// <summary> /// 实体字段标识 /// </summary> /// <param name="paramName">数据库字段名</param> /// <param name="propertyName">本字段对应的属性名</param> /// <param name="sqlType">对应的SQL数据类型</param> /// <param name="propertyType">属性类型</param> /// <param name="length">长度</param> public EntityParam(string fieldName, string paramName, string propertyName, DbType sqlType, EntityPropertyType propertyType, string description, int length, bool allowNull, bool isReadOnly) { this._fieldName = fieldName; this._paramName = paramName; this._propertyName = propertyName; this._sqlType = sqlType; this._propertyType = propertyType; this._length = length; this._allowNull = allowNull; this._readonly = isReadOnly; this._description = description; }
public EntityProperty(string Name, string Desc, EntityPropertyType Type, EntityPropertyLimits Limits, uint Flags = 0) : this(Name, Desc, Type) { if(Limits.max == 0 && Limits.min == 0) { limits.max = Sandbox.UIConstants.MAX_SLIDER_VALUE; } else { limits.max = Limits.max; limits.min = Limits.min; } flags = Flags; }
private Expression <Func <TEntity, bool> > DateTimeExpr(DateTimeFromToFilterComplex dateTimeFromToFilter, ParameterExpression item) { Expression <Func <TEntity, bool> > lambdaExpr; if (EntityPropertyType.IsNullable()) { var(fromDateExpressionInfo, toDateExpressionInfo) = BuildExpressionDateTimeInfo(dateTimeFromToFilter, true); MemberExpression memberExpression = dateTimeFromToFilter.TruncateTime ? Expression.Property(Expression.Property(PropertyOrField, "Value"), "Date") : PropertyOrField; var ifTrue = memberExpression .GreaterLessThanBuilderExpressions(fromDateExpressionInfo, toDateExpressionInfo, BitwiseOperationExpressions.AndAlso); var nullOrGreaterLess = Expression.AndAlso( Expression.Property(PropertyOrField, "HasValue"), ifTrue); lambdaExpr = nullOrGreaterLess.LambdaExpressionBuilder <TEntity>(item); } else { var(dateFromExprInfo, dateToExprInfo) = BuildExpressionDateTimeInfo(dateTimeFromToFilter, false); var entityPropTruncated = dateTimeFromToFilter.TruncateTime ? Expression.Property(PropertyOrField, "Date") : PropertyOrField; var dateTimeExpr = entityPropTruncated.GreaterLessThanBuilderExpressions(dateFromExprInfo, dateToExprInfo, BitwiseOperationExpressions.AndAlso); lambdaExpr = dateTimeExpr.LambdaExpressionBuilder <TEntity>(item); } return(lambdaExpr); }
/// <summary> /// 填充字段信息 /// </summary> /// <param name="prm">字段信息</param> /// <param name="reader">reader</param> private void FillParam(DBTableInfo table, IDataReader reader) { string prmName = reader["paramName"] as string; if (string.IsNullOrEmpty(prmName)) { return; } foreach (EntityParam ep in table.Params) { if (ep.ParamName == prmName) { return; } } EntityParam prm = new EntityParam(); prm.ParamName = prmName; EntityPropertyType type = EntityPropertyType.Normal; int isPrimary = Convert.ToInt32(reader["isPrimary"]); int isIdentity = Convert.ToInt32(reader["isIdentity"]); if (isPrimary == 1) { type = EntityPropertyType.PrimaryKey; } if (isIdentity == 1) { type = type | EntityPropertyType.Identity; } prm.AllowNull = Convert.ToBoolean(reader["allowNull"]); prm.PropertyType = type; prm.Length = Convert.ToInt64(reader["length"]); if (!table.IsView) { prm.Description = reader["paramDescription"] as string; } string strDBType = reader["dbType"] as string; prm.SqlType = GetDbType(strDBType); table.Params.Add(prm); }
/// <summary> /// 填充字段信息 /// </summary> /// <param name="table"></param> /// <param name="reader"></param> private void FillParam(DBTableInfo table, DataRow dr, DataTable dtDataTypes) { string prmName = dr["COLUMN_NAME"] as string; if (string.IsNullOrEmpty(prmName)) { return; } foreach (EntityParam ep in table.Params) { if (ep.ParamName == prmName) { return; } } EntityParam prm = new EntityParam(); prm.ParamName = prmName; EntityPropertyType type = EntityPropertyType.Normal; bool isPrimary = (!dr.IsNull("PRIMARY_KEY")) && ((bool)dr["PRIMARY_KEY"]); if (isPrimary) { type = EntityPropertyType.PrimaryKey; } bool isIdentity = (!dr.IsNull("AUTOINCREMENT")) && ((bool)dr["AUTOINCREMENT"]); if (isIdentity) { type = type | EntityPropertyType.Identity; } bool allowNull = (!dr.IsNull("IS_NULLABLE")) && ((bool)dr["IS_NULLABLE"]); prm.AllowNull = allowNull; prm.PropertyType = type; prm.Length = dr.IsNull("CHARACTER_MAXIMUM_LENGTH") ? 0 : (Convert.ToInt64(dr["CHARACTER_MAXIMUM_LENGTH"])); string strDBType = dr.IsNull("DATA_TYPE") ? "text" : (dr["DATA_TYPE"] as string); FillDbType(strDBType, prm, dtDataTypes); table.Params.Add(prm); }
private Expression <Func <TEntity, bool> > DefaultExpr() { var right = Expression.Constant(FilterPropertyValue); BinaryExpression binaryExpression; if (EntityPropertyType.IsNullable()) { var leftUnaryExpression = Expression.Convert(PropertyOrField, FilterPropertyValue.GetType()); binaryExpression = Expression.Equal(leftUnaryExpression, right); } else { binaryExpression = Expression.Equal(PropertyOrField, right); } var lambda = binaryExpression.LambdaExpressionBuilder <TEntity>(Item); return(lambda); }
public static EntityPropertyType GetEditorType(Type type, EntityPropertyType propertyType) { //If a special type is needed, do this here. switch (propertyType) { case EntityPropertyType.Object: case EntityPropertyType.Texture: case EntityPropertyType.File: case EntityPropertyType.Sound: case EntityPropertyType.Dialogue: case EntityPropertyType.Sequence: { if (type == typeof(string)) return propertyType; throw new EntityException("File selector type was specified, but property was not a string."); } case EntityPropertyType.Color: { if (type == typeof(Vec3)) return propertyType; throw new EntityException("Vector type was specified, but property was not a vector."); } } //OH PROGRAMMING GODS, FORGIVE ME if (type == typeof(string)) return EntityPropertyType.String; if (type == typeof(int)) return EntityPropertyType.Int; if (type == typeof(float) || type == typeof(double)) return EntityPropertyType.Float; if (type == typeof(bool)) return EntityPropertyType.Bool; if (type == typeof(Vec3)) return EntityPropertyType.Vec3; throw new EntityException("Invalid property type specified."); }
/// <summary> /// 填充字段信息 /// </summary> /// <param name="prm">字段信息</param> /// <param name="reader">reader</param> private void FillParam(DBTableInfo table, IDataReader reader) { string prmName = reader["COLNAME"] as string; if (string.IsNullOrEmpty(prmName)) { return; } foreach (EntityParam ep in table.Params) { if (ep.ParamName == prmName) { return; } } EntityParam prm = new EntityParam(); prm.ParamName = prmName; EntityPropertyType type = EntityPropertyType.Normal; int isPrimary = 0; object val = reader["KEYSEQ"]; if (!(val is DBNull)) { isPrimary = Convert.ToInt32(val); } val = reader["IDENTITY"]; bool isIdentity = false; if (!(val is DBNull)) { isIdentity = val.ToString().Equals("Y", StringComparison.CurrentCultureIgnoreCase); } if (isPrimary == 1) { type = EntityPropertyType.PrimaryKey; } if (isIdentity) { type = type | EntityPropertyType.Identity; } val = reader["NULLS"]; bool isNull = false; if (!(val is DBNull)) { isNull = val.ToString().Equals("Y", StringComparison.CurrentCultureIgnoreCase); } prm.AllowNull = isNull; prm.PropertyType = type; prm.Length = Convert.ToInt64(reader["LENGTH"]); if (!table.IsView) { prm.Description = reader["REMARKS"] as string; } string strDBType = reader["TYPENAME"] as string; prm.SqlType = GetDbType(strDBType); table.Params.Add(prm); }
extern public static void RegisterComponentProperty(Type type, PropertyInfo propertyInfo, string name, string label, string description, EntityPropertyType propertyType);
public ViewDataAttribute(string name, EntityPropertyType epType) { Name = name; EntityPropertyType = epType; }
private string GetSecondLevelType(EntityPropertyType propertyType) { return propertyType == EntityPropertyType.Property ? "'column'" : "'constraint'"; }
/// <summary> /// Initializes a new <see cref="EntityProperty"/>. /// </summary> /// <param name="name">The property name</param> /// <param name="type">The property type</param> public EntityProperty(string name, EntityPropertyType type) { Name = name; Type = type; }
/// <summary> /// 实体字段标识 /// </summary> /// <param name="paramName">数据库字段名</param> /// <param name="propertyName">本字段对应的属性名</param> /// <param name="sqlType">对应的SQL数据类型</param> /// <param name="propertyType">属性类型</param> public EntityParam(string fieldName, string paramName, string propertyName, DbType sqlType, EntityPropertyType propertyType, string description) : this(fieldName, paramName, propertyName, sqlType, propertyType, description, 0, true, false) { }
private static string GetSecondLevelType(EntityPropertyType propertyType) => propertyType == EntityPropertyType.Property ? "'column'" : "'constraint'";
/// <summary> /// Ctor /// </summary> /// <param name="type">Either a value type, a reference type, or a reference list.</param> /// <param name="column">The column mapped to this property. Can be null.</param> public EntityPropertyAttribute(EntityPropertyType type, string column) { Type = type; if (column == null) ColumnName = string.Empty; ColumnName = column; }
// constructors /// <summary> /// Initializes an member of EntityPropertyAttribute. /// </summary> /// <param name="propertyType">Entity type of the property.</param> public EntityPropertyAttribute(EntityPropertyType propertyType) { _propertyType = propertyType; }
public EntityPropertyAttribute(EntityPropertyType type = EntityPropertyType.Primitive, string description = null) { Description = description; Type = type; }
/// <summary> /// Called when the user changes a property from within the Editor. /// </summary> /// <param name="memberInfo"></param> /// <param name="propertyType"></param> /// <param name="newValue"></param> protected virtual void OnPropertyChanged(MemberInfo memberInfo, EntityPropertyType propertyType, object newValue) { }
public virtual void SetPropertyValue(string propertyName, EntityPropertyType propertyType, string value) { if(value.Length <= 0 && propertyType != EntityPropertyType.String) return; if(!memberIsProperty.ContainsKey(propertyName)) { if(GetType().GetProperty(propertyName) != null) memberIsProperty.Add(propertyName, true); else if(GetType().GetField(propertyName) != null) memberIsProperty.Add(propertyName, false); else throw new Exception("The specified property name does not exist. This really shouldn't happen."); } var isProperty = memberIsProperty[propertyName]; // Store properties so we can utilize the get set functionality after opening a saved level. if(!Spawned && isProperty) { if(storedProperties == null) storedProperties = new Dictionary<string[], EntityPropertyType>(); storedProperties.Add(new string[] { propertyName, value }, propertyType); return; } switch(propertyType) { case EntityPropertyType.Bool: { if(isProperty) GetType().GetProperty(propertyName).SetValue(this, Convert.ToBoolean(value), null); else GetType().GetField(propertyName).SetValue(this, Convert.ToBoolean(value)); } break; case EntityPropertyType.Int: { if(isProperty) GetType().GetProperty(propertyName).SetValue(this, Convert.ToInt32(value), null); else GetType().GetField(propertyName).SetValue(this, Convert.ToInt32(value)); } break; case EntityPropertyType.Float: { if(isProperty) GetType().GetProperty(propertyName).SetValue(this, Convert.ToSingle(value), null); else GetType().GetField(propertyName).SetValue(this, Convert.ToSingle(value)); } break; case EntityPropertyType.Vec3: { string[] split = value.Split(','); var vec = new Vec3(Convert.ToSingle(split[0]), Convert.ToSingle(split[1]), Convert.ToSingle(split[2])); if(isProperty) GetType().GetProperty(propertyName).SetValue(this, vec, null); else GetType().GetField(propertyName).SetValue(this, vec); } break; case EntityPropertyType.String: { if(isProperty) GetType().GetProperty(propertyName).SetValue(this, value, null); else GetType().GetField(propertyName).SetValue(this, value); } break; } }
/// 填充字段信息 /// </summary> /// <param name="prm">字段信息</param> /// <param name="reader">reader</param> private void FillParam(DBTableInfo table, IDataReader reader) { string prmName = reader["COLUMN_NAME"] as string; if (string.IsNullOrEmpty(prmName)) { return; } foreach (EntityParam ep in table.Params) { if (ep.ParamName == prmName) { return; } } EntityParam prm = new EntityParam(); prm.ParamName = prmName; EntityPropertyType type = EntityPropertyType.Normal; bool isIdentity = false; bool isPrimaryKey = false; string extra = reader["EXTRA"] as string; if (!string.IsNullOrEmpty(extra) && extra.Trim().Equals("auto_increment", StringComparison.CurrentCultureIgnoreCase)) { isIdentity = true; } string columnKey = reader["COLUMN_KEY"] as string; if (!string.IsNullOrEmpty(columnKey) && columnKey.Trim().Equals("PRI", StringComparison.CurrentCultureIgnoreCase)) { isPrimaryKey = true; } if (isPrimaryKey) { type = EntityPropertyType.PrimaryKey; } if (isIdentity) { type = type | EntityPropertyType.Identity; } prm.PropertyType = type; if (!(reader["CHARACTER_OCTET_LENGTH"] is DBNull)) { prm.Length = Convert.ToInt64(reader["CHARACTER_OCTET_LENGTH"]); } if (!table.IsView) { prm.Description = reader["COLUMN_COMMENT"] as string; } prm.AllowNull = Convert.ToInt32(reader["IS_NULLABLE"]) == 1; string strDBType = reader["COLUMN_TYPE"] as string; bool isUnsigned = strDBType.IndexOf("unsigned") > -1; string strDataType = reader["DATA_TYPE"] as string; prm.SqlType = GetDbType(strDataType, isUnsigned); table.Params.Add(prm); }
extern public static void RegisterComponentProperty(Type componentType, PropertyInfo propertyInfo, string name, string label, string description, EntityPropertyType propertyType, object defaultValue);
protected override void OnPropertyChanged(System.Reflection.MemberInfo memberInfo, EntityPropertyType propertyType, object newValue) { Activate(Activated, true); }
private Expression <Func <TEntity, bool> > DateTimeExpr(DateTimeFromToFilter dateTimeFromToFilter, ParameterExpression item) { var dateTimeValueDateFrom = dateTimeFromToFilter.DateFrom; // (DateTimeValue) propertiesDateTime[0].GetValue(propertyValue); var dateTimeValueDateTo = dateTimeFromToFilter.DateTo; // var bitwiseOperation = dateTimeFromToFilter.BitwiseOperation; var fromDate = dateTimeValueDateFrom.DateTime; DateTime?toDate = default; (ConstantExpression rightToDate, CompareExpressionType? ExpressionType)dateToInfoTuple = default; CompareExpressionType dateToExprType = default; if (dateTimeValueDateTo != null) { dateToExprType = dateTimeValueDateTo.ExpressionType ?? CompareExpressionType.LessThanOrEqual; toDate = dateTimeValueDateTo.DateTime; if (toDate.HasValue) { var rightToDate = Expression.Constant(toDate.Value.Date); dateToInfoTuple = (rightToDate, dateToExprType); } } var rightFromDate = Expression.Constant(fromDate.Value.Date); var dateFromExprType = dateTimeValueDateFrom.ExpressionType ?? CompareExpressionType.GreaterThanOrEqual; var dateFromInfoTuple = (rightFromDate, compareExpressionType: dateFromExprType); Expression <Func <TEntity, bool> > lambdaExpr; if (EntityPropertyType.IsNullable()) { var ifTrue = Expression.Property(Expression.Property(PropertyOrField, "Value"), "Date") .GreaterLessThanBuilderExpressions(dateFromInfoTuple, dateToInfoTuple, BitwiseOperationExpressions.AndAlso); var ifFalse = PropertyOrField.GreaterLessThanBuilderExpressions( (Expression.Constant(fromDate, typeof(DateTime?)), dateFromExprType), toDate == null ? default : (Expression.Constant(toDate, typeof(DateTime?)), dateToExprType), BitwiseOperationExpressions.AndAlso); var conditionalExpression = Expression.Condition(Expression.Property(PropertyOrField, "HasValue"), ifTrue, ifFalse); lambdaExpr = conditionalExpression.LambdaExpressionBuilder <TEntity>(item); } else { var entityPropTruncated = Expression.Property(PropertyOrField, "Date"); var dateTimeExpr = entityPropTruncated.GreaterLessThanBuilderExpressions(dateFromInfoTuple, dateToInfoTuple, BitwiseOperationExpressions.AndAlso); lambdaExpr = dateTimeExpr.LambdaExpressionBuilder <TEntity>(item); } return(lambdaExpr); }
/// <summary> /// Ctor /// </summary> /// <param name="type">Either a value type, a reference type, or a reference list.</param> public EntityPropertyAttribute(EntityPropertyType type) : this(type, string.Empty) { }
internal virtual void SetPropertyValue(string propertyName, EntityPropertyType propertyType, string valueString) { #if !((RELEASE && RELEASE_DISABLE_CHECKS)) if (valueString == null) throw new ArgumentNullException("valueString"); if (propertyName == null) throw new ArgumentNullException("propertyName"); if (valueString.Length < 1 && propertyType != EntityPropertyType.String) throw new ArgumentException("value was empty!"); if (propertyName.Length < 1) throw new ArgumentException("propertyName was empty!"); #endif var value = Convert.FromString(propertyType, valueString); var member = GetType().GetMember(propertyName).First(x => x.MemberType == MemberTypes.Field || x.MemberType == MemberTypes.Property); if (member == null) throw new ArgumentException(string.Format("member {0} could not be located", propertyName)); if (member.MemberType == MemberTypes.Property) (member as PropertyInfo).SetValue(this, value, null); else (member as FieldInfo).SetValue(this, value); OnPropertyChanged(member, propertyType, value); }
/// 填充字段信息 /// </summary> /// <param name="prm">字段信息</param> /// <param name="reader">reader</param> private void FillParam(DBTableInfo table, IDataReader reader) { string prmName = reader["column_name"] as string; if (string.IsNullOrEmpty(prmName)) { return; } foreach (EntityParam ep in table.Params) { if (ep.ParamName == prmName) { return; } } EntityParam prm = new EntityParam(); prm.ParamName = prmName; EntityPropertyType type = EntityPropertyType.Normal; bool isIdentity = false; bool isPrimaryKey = false; string columnKey = reader["constraint_type"] as string; if (!string.IsNullOrEmpty(columnKey)) { isPrimaryKey = true; isIdentity = true; } if (isPrimaryKey) { type = EntityPropertyType.PrimaryKey; } if (isIdentity) { type = type | EntityPropertyType.Identity; } prm.PropertyType = type; object val = reader["character_maximum_length"]; if (!(val is DBNull)) { prm.Length = Convert.ToInt64(val); } val = reader["is_nullable"]; if (!(val is DBNull)) { prm.AllowNull = val.ToString().Equals("YES", StringComparison.CurrentCultureIgnoreCase); } string strDataType = reader["udt_name"] as string; prm.SqlType = GetDbType(strDataType); table.Params.Add(prm); }