internal static Expression Assign(this Expression path, Type converterType, Expression value, AssignLogInfo toLog = null) { if (!MutatorsAssignRecorder.IsRecording() || toLog == null) { return(path.InternalAssign(converterType, value)); } MutatorsAssignRecorder.RecordCompilingExpression(converterType, toLog); MethodCallExpression recordingExpression; var temp = Expression.Variable(value.Type, "temp"); if (value.Type.IsNullable()) { recordingExpression = Expression.Call(RecordingMethods.RecordExecutingExpressionWithNullableValueCheckGenericMethodInfo.MakeGenericMethod(Nullable.GetUnderlyingType(value.Type)), Expression.Constant(converterType, typeof(Type)), Expression.Constant(toLog), value); } else if (value.Type.IsValueType) { recordingExpression = Expression.Call(RecordingMethods.RecordExecutingExpressionMethodInfo, Expression.Constant(converterType, typeof(Type)), Expression.Constant(toLog)); } else { recordingExpression = Expression.Call(RecordingMethods.RecordExecutingExpressionWithValueObjectCheck, Expression.Constant(converterType, typeof(Type)), Expression.Constant(toLog), value); } return(Expression.Block(new[] { temp }, Expression.Assign(temp, value), path.InternalAssign(converterType, temp), recordingExpression, temp)); }
protected virtual void BeforeConvert(TSource source) { if (MutatorsAssignRecorder.IsRecording()) { MutatorsAssignRecorder.RecordConverter(GetType().Name); } }
protected virtual void AfterConvert(TDest dest, TSource source) { if (MutatorsAssignRecorder.IsRecording()) { MutatorsAssignRecorder.StopRecordingConverter(); } }
public Func <TSource, TDest> GetConverter(MutatorsContext context) { if (MutatorsAssignRecorder.IsRecording()) { MutatorsAssignRecorder.RecordConverter(GetType().Name); } return(GetOrCreateHashtableSlot(context).Converter); }
public override Expression Apply(Expression path, List <KeyValuePair <Expression, Expression> > aliases) { if (Condition == null) { return(null); } var infoToLog = new AssignLogInfo(path, Expression.Constant(ToString(), typeof(string))); var condition = Expression.Equal(Expression.Convert(Condition.Body.ResolveAliases(aliases), typeof(bool?)), Expression.Constant(true, typeof(bool?))); path = PrepareForAssign(path); var applyResult = Expression.IfThen(condition, Expression.Assign(path, Expression.Constant(path.Type.GetDefaultValue(), path.Type))); if (MutatorsAssignRecorder.IsRecording()) { MutatorsAssignRecorder.RecordCompilingExpression(infoToLog); return(Expression.Block(Expression.Call(typeof(MutatorsAssignRecorder).GetMethod("RecordExecutingExpression"), Expression.Constant(infoToLog)), applyResult)); } return(applyResult); }