Example #1
0
        /// <summary>
        /// Creates a matching for type cast expressions.
        /// </summary>
        /// <param name="srcType">source type</param>
        /// <param name="dstType">destination type</param>
        public Matching Cast(Type srcType, TypeDescriptor dstType)
        {
            var      cast = IntrinsicFunctions.Cast((Expression)null, srcType, dstType);
            Matching newm = new Matching();

            newm._func = e => e.NodeEquals(cast) &&
                         this.Match(e.Children.ElementAt(0));
            newm._gen = () => newm._expr == null?
                        IntrinsicFunctions.Cast(_gen(), srcType, dstType) :
                            newm._expr;

            return(newm);
        }
Example #2
0
 private static Expression ToExpression(object arg)
 {
     if (arg is Expression)
     {
         var ex = (Expression)arg;
         if (ex.ResultType.CILType.Equals(typeof(string)))
         {
             return(ex);
         }
         else
         {
             return(IntrinsicFunctions.Cast(ex, ex.ResultType.CILType, typeof(string)));
         }
     }
     else if (arg is ILiteral)
     {
         return(ToExpression(new LiteralReference((ILiteral)arg)));
     }
     else
     {
         return(LiteralReference.CreateConstant(arg.ToString()));
     }
 }