예제 #1
0
        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));
        }
예제 #2
0
 protected virtual void BeforeConvert(TSource source)
 {
     if (MutatorsAssignRecorder.IsRecording())
     {
         MutatorsAssignRecorder.RecordConverter(GetType().Name);
     }
 }
예제 #3
0
 protected virtual void AfterConvert(TDest dest, TSource source)
 {
     if (MutatorsAssignRecorder.IsRecording())
     {
         MutatorsAssignRecorder.StopRecordingConverter();
     }
 }
예제 #4
0
 public Func <TSource, TDest> GetConverter(MutatorsContext context)
 {
     if (MutatorsAssignRecorder.IsRecording())
     {
         MutatorsAssignRecorder.RecordConverter(GetType().Name);
     }
     return(GetOrCreateHashtableSlot(context).Converter);
 }
예제 #5
0
        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);
        }