Esempio n. 1
0
            public Expression GetFinalValueOrNull()
            {
                var finalDataSource = _dataSources.Last();
                var finalValue      = finalDataSource.Value;

                if (!finalDataSource.IsFallback)
                {
                    return(finalValue);
                }

                if (finalValue.NodeType == ExpressionType.Coalesce)
                {
                    // Coalesce between the existing target member value and the fallback:
                    return(((BinaryExpression)finalValue).Right);
                }

                var targetMemberAccess = MapperData.GetTargetMemberAccess();

                if (ExpressionEvaluation.AreEqual(finalValue, targetMemberAccess))
                {
                    return(null);
                }

                return(finalValue);
            }
Esempio n. 2
0
        private static bool Verify(Expression one, Expression two)
        {
#if NET35
            return(ExpressionEvaluation.AreEqual(one.ToDlrExpression(), two.ToDlrExpression()));
#else
            return(ExpressionEvaluation.AreEqual(one, two));
#endif
        }
        public bool IsSameAs(IDataSource otherDataSource)
        {
            if (IsConditional &&
                otherDataSource.IsConditional &&
                ExpressionEvaluation.AreEqual(Condition, otherDataSource.Condition))
            {
                return(true);
            }

            return(ExpressionEvaluation.AreEquivalent(otherDataSource.Value, _originalValue));
        }
Esempio n. 4
0
        private static bool TryAdjustToSingleUseableDataSource(
            ref IList <IDataSource> dataSources,
            IMemberMapperData mapperData)
        {
            var finalDataSource = dataSources.Last();

            if (!finalDataSource.IsFallback)
            {
                return(false);
            }

            var finalValue = finalDataSource.Value;

            if (finalValue.NodeType == ExpressionType.Coalesce)
            {
                // Coalesce between the existing target member value and the fallback:
                dataSources[dataSources.Count - 1] = new AdHocDataSource(
                    finalDataSource.SourceMember,
                    ((BinaryExpression)finalValue).Right,
                    finalDataSource.Condition,
                    finalDataSource.Variables);

                return(false);
            }

            var targetMemberAccess = mapperData.GetTargetMemberAccess();

            if (!ExpressionEvaluation.AreEqual(finalValue, targetMemberAccess))
            {
                return(false);
            }

            if (dataSources.Count == 2)
            {
                return(true);
            }

            var dataSourcesWithoutFallback = new IDataSource[dataSources.Count - 1];

            dataSourcesWithoutFallback.CopyFrom(dataSources);
            dataSources = dataSourcesWithoutFallback;
            return(false);
        }
                public bool Equals(Expression x, Expression y)
                {
                    if (x?.NodeType != ExpressionType.Call || y?.NodeType != ExpressionType.Call)
                    {
                        return(false);
                    }

                    var methodCallX = (MethodCallExpression)x;

                    if (methodCallX.Method.IsStatic)
                    {
                        return(false);
                    }

                    var methodCallY = (MethodCallExpression)y;

                    return((methodCallX.Method == methodCallY.Method) &&
                           (methodCallX.Object.NodeType == ExpressionType.Constant) &&
                           (methodCallY.Object.NodeType == ExpressionType.Constant) &&
                           ExpressionEvaluation.AreEqual(methodCallX.Object, methodCallY.Object));
                }
Esempio n. 6
0
        private Expression GetFallbackValueOrNull()
        {
            var finalDataSource = _dataSources.Last();
            var fallbackValue   = finalDataSource.Value;

            if (finalDataSource.IsConditional || _dataSources.HasOne())
            {
                return(fallbackValue);
            }

            if (fallbackValue.NodeType == ExpressionType.Coalesce)
            {
                return(((BinaryExpression)fallbackValue).Right);
            }

            var targetMemberAccess = MapperData.GetTargetMemberAccess();

            if (ExpressionEvaluation.AreEqual(fallbackValue, targetMemberAccess))
            {
                return(null);
            }

            return(fallbackValue);
        }