コード例 #1
0
        Expression ILiteralEncodingStrategy.Array(EncoderVisitor visitor, IList <LiteralNode> elements)
        {
            NativeLiteralArrayVisitor arrayVisitor = new NativeLiteralArrayVisitor(visitor);

            Expression[] items = new Expression[elements.Count];
            for (int i = 0; i < items.Length; i++)
            {
                items[i] = elements[i].Accept(arrayVisitor);
            }

            Expression initializer = Expression.NewArrayInit(typeof(object), items);
            NativeLiteralArrayVisitor outerArrrayVisitor = visitor.GetNativeLiteralArrayVisitor();

            if (outerArrrayVisitor != null)
            {
                outerArrrayVisitor.HadSymbols = outerArrrayVisitor.HadSymbols | arrayVisitor.HadSymbols;
                return(initializer); // Embed in outer array
            }

            // Root (outer-most) array visitor
            if (!arrayVisitor.HadSymbols)
            {
                return(this.DefineLiteral(visitor, "Array", initializer));
            }

            // Special handling if the array contains symbols.
            FieldInfo             field  = this.LiteralGenerator.DefineLiteralField("Array", initializer);
            ArrayBinderDefinition binder = new ArrayBinderDefinition(field);

            return(this.GenerateLiteralCallSite(visitor, binder, "Array"));
        }
コード例 #2
0
        Expression ILiteralEncodingStrategy.Symbol(EncoderVisitor visitor, string value)
        {
            NativeLiteralArrayVisitor arrayVisitor = visitor.GetNativeLiteralArrayVisitor();

            if (arrayVisitor != null)
            {
                // If inside a literal array, special handling ... return a SymbolPlaceholder instead.
                arrayVisitor.HadSymbols = true;
                return(Expression.Convert(Expression.New(NativeLiteralEncodingStrategy.SymbolPlaceholderCtor, Expression.Constant(value, typeof(string))), typeof(object)));
            }

            SymbolBinderDefinition binder = new SymbolBinderDefinition(value);

            return(this.GenerateLiteralCallSite(visitor, binder, value));
        }