Example #1
0
            protected internal override Expression VisitConstant(ConstantExpression node)
            {
                // if we've promoted a value to a templated constant turn it
                // back into a normal constant for the purpose of comparing the trees
                ITemplatedValue tempVal = node.Value as ITemplatedValue;

                if (tempVal != null)
                {
                    if (_templated == null)
                    {
                        _templated = new Dictionary <ConstantExpression, ConstantExpression>();
                    }

                    // if we have templated constants we need to make sure to remember their
                    // templated to see if the resulting rules will be compatible.
                    ConstantExpression newConstant = Expression.Constant(tempVal.ObjectValue, tempVal.GetType().GetGenericArguments()[0]);

                    _templated[newConstant] = newConstant;
                    Expressions.Add(newConstant);
                }
                else
                {
                    Expressions.Add(node);
                }
                return(base.VisitConstant(node));
            }
Example #2
0
        private static string Constant(object value)
        {
            if (value == null)
            {
                return(".null");
            }

            ITemplatedValue itv = value as ITemplatedValue;

            if (itv != null)
            {
                return(".template" + itv.Index.ToString(CultureInfo.CurrentCulture) + " (" + itv.ObjectValue.ToString() + ")");
            }

            string s;

            if ((s = value as string) != null)
            {
                return("\"" + s + "\"");
            }
            if (value is int || value is double)
            {
                return(String.Format(CultureInfo.CurrentCulture, "{0:G}", value));
            }
            if (value is bool)
            {
                return(value.ToString());
            }
            return(".const<" + value.GetType().Name + ">(" + value.ToString() + ")");
        }
Example #3
0
        private static object[] CopyArray(object[] newData, object[] oldData)
        {
            object[] res = new object[oldData.Length];
            for (int i = 0; i < oldData.Length; i++)
            {
                ITemplatedValue itv = oldData[i] as ITemplatedValue;
                if (itv == null)
                {
                    res[i] = oldData[i];
                    continue;
                }

                res[i] = itv.CopyWithNewValue(newData[itv.Index]);
            }
            return(res);
        }
Example #4
0
        private static Tuple CopyTuple(object[] newData, Tuple oldTuple)
        {
            Tuple res = (Tuple)Activator.CreateInstance(oldTuple.GetType());

            for (int i = 0; i < oldTuple.Capacity; i++)
            {
                ITemplatedValue itv = oldTuple.GetValue(i) as ITemplatedValue;
                if (itv == null)
                {
                    res.SetValue(i, res.GetValue(i));
                }

                res.SetValue(i, itv.CopyWithNewValue(newData[i]));
            }
            return(res);
        }
Example #5
0
        private static object[] CopyArray(object[] newData, object[] oldData)
        {
            int copiedCount = 0;

            object[] res = new object[oldData.Length];
            for (int i = 0; i < oldData.Length; i++)
            {
                ITemplatedValue itv = oldData[i] as ITemplatedValue;
                if (itv == null)
                {
                    res[i] = oldData[i];
                    continue;
                }
                copiedCount++;

                res[i] = itv.CopyWithNewValue(newData[itv.Index]);
            }

            Debug.Assert(copiedCount == newData.Length);
            return(res);
        }