public CoordinatorFactory( int depth, int stateSlot, Expression hasData, Expression setKeys, Expression checkKeys, CoordinatorFactory[] nestedCoordinators, Expression element, Expression elementWithErrorHandling, Expression initializeCollection, RecordStateFactory[] recordStateFactories) : this( depth, stateSlot, CodeGenEmitter.BuildShaperLambda <bool>(hasData), CodeGenEmitter.BuildShaperLambda <bool>(setKeys), CodeGenEmitter.BuildShaperLambda <bool>(checkKeys), nestedCoordinators, typeof(IEntityWrapper).IsAssignableFrom(element.Type) ? null : CodeGenEmitter.BuildShaperLambda <TElement>(element), typeof(IEntityWrapper).IsAssignableFrom(element.Type) ? CodeGenEmitter.BuildShaperLambda <IEntityWrapper>(element) : null, CodeGenEmitter.BuildShaperLambda <TElement>( typeof(IEntityWrapper).IsAssignableFrom(element.Type) ? CodeGenEmitter.Emit_UnwrapAndEnsureType(elementWithErrorHandling, typeof(TElement)) : elementWithErrorHandling), CodeGenEmitter.BuildShaperLambda <ICollection <TElement> >(initializeCollection), recordStateFactories) { }
public RecordStateFactory( int stateSlotNumber, int columnCount, RecordStateFactory[] nestedRecordStateFactories, DataRecordInfo dataRecordInfo, Expression gatherData, string[] propertyNames, TypeUsage[] typeUsages) : this(stateSlotNumber, columnCount, nestedRecordStateFactories, dataRecordInfo, CodeGenEmitter.BuildShaperLambda <bool>(gatherData), propertyNames, typeUsages, isColumnNested : null) { }
internal override Expression Visit(Expression expression) { if (expression == null) { return(expression); } Expression expression1; Expression expression2; if (this._replacementDictionary != null && this._replacementDictionary.TryGetValue(expression, out expression1)) { expression2 = expression1; } else { bool flag = false; LambdaExpression lambdaExpression = (LambdaExpression)null; if (expression.NodeType == ExpressionType.Lambda && this._inlineDelegates != null) { lambdaExpression = (LambdaExpression)expression; flag = this._inlineDelegates.Contains(lambdaExpression); } if (flag) { Expression body = this.Visit(lambdaExpression.Body); expression2 = (Expression)Expression.Constant(CodeGenEmitter.Compile(body.Type, body)); } else { expression2 = base.Visit(expression); } } return(expression2); }
internal static Expression Emit_Conditional_NotDBNull( Expression result, int ordinal, Type columnType) { result = (Expression) Expression.Condition(CodeGenEmitter.Emit_Reader_IsDBNull(ordinal), (Expression) Expression.Constant(TypeSystem.GetDefaultValue(columnType), columnType), result); return result; }
internal override Expression Visit(Expression expression) { if (null == expression) { return(expression); } Expression result; // check to see if a substitution has been provided for this expression Expression replacement; if (null != _replacementDictionary && _replacementDictionary.TryGetValue(expression, out replacement)) { // once a substitution is found, we stop walking the sub-expression and // return immediately (since recursive replacement is not needed or wanted) result = replacement; } else { // check if we need to precompile an inline delegate var preCompile = false; LambdaExpression lambda = null; if (expression.NodeType == ExpressionType.Lambda && null != _inlineDelegates) { lambda = (LambdaExpression)expression; preCompile = _inlineDelegates.Contains(lambda); } if (preCompile) { // do replacement in the body of the lambda expression var body = Visit(lambda.Body); // compile to a delegate result = Expression.Constant(CodeGenEmitter.Compile(body.Type, body)); } else { result = base.Visit(expression); } } return(result); }
internal static Expression Emit_EnsureTypeAndWrap( Expression input, Expression keyReader, Expression entitySetReader, Type requestedType, Type identityType, Type actualType, MergeOption mergeOption, bool isProxy) { Expression input1 = CodeGenEmitter.Emit_EnsureType(input, requestedType); if (!requestedType.IsClass()) input1 = CodeGenEmitter.Emit_EnsureType(input, typeof (object)); return CodeGenEmitter.CreateEntityWrapper(CodeGenEmitter.Emit_EnsureType(input1, actualType), keyReader, entitySetReader, actualType, identityType, mergeOption, isProxy); }
private static T GetTypedValueDefault(DbDataReader reader, int ordinal) { Type underlyingType = Nullable.GetUnderlyingType(typeof(T)); if (underlyingType != (Type)null && underlyingType.IsEnum()) { return((T)Shaper.ErrorHandlingValueReader <T> .GetGenericTypedValueDefaultMethod(underlyingType).Invoke((object)null, new object[2] { (object)reader, (object)ordinal })); } bool isNullable; return((T)CodeGenEmitter.GetReaderMethod(typeof(T), out isNullable).Invoke((object)reader, new object[1] { (object)ordinal })); }
private static T GetTypedValueDefault(DbDataReader reader, int ordinal) { var underlyingType = Nullable.GetUnderlyingType(typeof(T)); // The value read from the reader is of a primitive type. Such a value cannot be cast to a nullable enum type directly // but first needs to be cast to the non-nullable enum type. Therefore we will call this method for non-nullable // underlying enum type and cast to the target type. if (underlyingType != null && underlyingType.IsEnum()) { var methodInfo = GetGenericTypedValueDefaultMethod(underlyingType); return((T)methodInfo.Invoke(null, new object[] { reader, ordinal })); } // use the specific reader.GetXXX method bool isNullable; var readerMethod = CodeGenEmitter.GetReaderMethod(typeof(T), out isNullable); var result = (T)readerMethod.Invoke(reader, new object[] { ordinal }); return(result); }
private static T GetTypedValueDefault(DbDataReader reader, int ordinal) { var underlyingType = Nullable.GetUnderlyingType(typeof(T)); // The value read from the reader is of a primitive type. Such a value cannot be cast to a nullable enum type directly // but first needs to be cast to the non-nullable enum type. Therefore we will call this method for non-nullable // underlying enum type and cast to the target type. if (underlyingType != null && underlyingType.IsEnum) { var type = typeof(ErrorHandlingValueReader <>).MakeGenericType(underlyingType); return((T)type.GetMethod( MethodBase.GetCurrentMethod().Name, BindingFlags.NonPublic | BindingFlags.Static).Invoke( null, new object[] { reader, ordinal })); } // use the specific reader.GetXXX method bool isNullable; var readerMethod = CodeGenEmitter.GetReaderMethod(typeof(T), out isNullable); var result = (T)readerMethod.Invoke(reader, new object[] { ordinal }); return(result); }
internal static Expression Emit_UnwrapAndEnsureType(Expression input, Type type) { return CodeGenEmitter.Emit_EnsureType((Expression) Expression.Property(input, CodeGenEmitter.IEntityWrapper_Entity), type); }
internal static Expression Emit_Shaper_GetState(int stateSlotNumber, Type type) { return CodeGenEmitter.Emit_EnsureType((Expression) Expression.ArrayIndex(CodeGenEmitter.Shaper_State, (Expression) Expression.Constant((object) stateSlotNumber)), type); }
internal static Expression Emit_Reader_IsDBNull(ColumnMap columnMap) { return CodeGenEmitter.Emit_Reader_IsDBNull(((ScalarColumnMap) columnMap).ColumnPos); }
internal static Expression Emit_Reader_GetValue(int ordinal, Type type) { return CodeGenEmitter.Emit_EnsureType((Expression) Expression.Call(CodeGenEmitter.Shaper_Reader, CodeGenEmitter.DbDataReader_GetValue, (Expression) Expression.Constant((object) ordinal)), type); }
internal static Expression Emit_NullConstant(Type type) { return !type.IsNullable() ? CodeGenEmitter.Emit_EnsureType((Expression) Expression.Constant((object) null, typeof (object)), type) : (Expression) Expression.Constant((object) null, type); }
internal static Expression Emit_EntityKey_HasValue(SimpleColumnMap[] keyColumns) { return (Expression) Expression.Not(CodeGenEmitter.Emit_Reader_IsDBNull((ColumnMap) keyColumns[0])); }
internal static Func<Shaper, TResult> Compile<TResult>(Expression body) { return CodeGenEmitter.BuildShaperLambda<TResult>(body).Compile(); }