public override void GenerateStartBlockCode (Block target, CodeGeneratorContext context)
		{
			if (context.Host.DesignTimeMode)
				return;

			Block child = target.Children.Where (n => n.IsBlock).Cast<Block> ().FirstOrDefault ();
			isExpression = child != null && child.Type == BlockType.Expression;

			var sb = new StringBuilder ();
			sb.Append (", Tuple.Create<string,object,bool> (");
			sb.WriteCStyleStringLiteral (Prefix.Value);
			sb.Append (", ");

			if (isExpression) {
				oldRenderingMode = context.GetExpressionRenderingMode ();
				context.SetExpressionRenderingMode (ExpressionRenderingMode.InjectCode);
			} else {
				sb.AppendFormat (
					"new {0} ({1} => {{",
					context.Host.GeneratedClassContext.TemplateTypeName,
					ValueWriterName);
			}

			context.MarkEndOfGeneratedCode ();
			context.BufferStatementFragment (sb.ToString ());

			oldTargetWriter = context.TargetWriterName;
			context.TargetWriterName = ValueWriterName;
		}
예제 #2
0
        protected override void Visit(DynamicCodeAttributeChunk chunk)
        {
            if (Context.Host.DesignTimeMode)
            {
                return; // Don't generate anything!
            }

            Chunk code = chunk.Children.FirstOrDefault();
            ExpressionRenderingMode currentRenderingMode = Context.ExpressionRenderingMode;
            string currentTargetWriterName = Context.TargetWriterName;

            Context.TargetWriterName = ValueWriterName;

            Writer.WriteParameterSeparator()
            .WriteLine();

            if (code is ExpressionChunk || code is ExpressionBlockChunk)
            {
                Writer.WriteStartMethodInvocation("Tuple.Create")
                .WriteLocationTaggedString(chunk.Prefix)
                .WriteParameterSeparator()
                .WriteStartMethodInvocation("Tuple.Create", new string[] { "System.Object", "System.Int32" });

                Context.ExpressionRenderingMode = ExpressionRenderingMode.InjectCode;

                Accept(code);

                Writer.WriteParameterSeparator()
                .Write(chunk.Start.AbsoluteIndex.ToString(CultureInfo.CurrentCulture))
                .WriteEndMethodInvocation(false)
                .WriteParameterSeparator()
                .WriteBooleanLiteral(false)
                .WriteEndMethodInvocation(false);
            }
            else
            {
                Writer.WriteStartMethodInvocation("Tuple.Create")
                .WriteLocationTaggedString(chunk.Prefix)
                .WriteParameterSeparator()
                .WriteStartMethodInvocation("Tuple.Create", new string[] { "System.Object", "System.Int32" })
                .WriteStartNewObject(Context.Host.GeneratedClassContext.TemplateTypeName);

                using (Writer.BuildLambda(endLine: false, parameterNames: ValueWriterName))
                {
                    Accept(chunk.Children);
                }

                Writer.WriteEndMethodInvocation(false)
                .WriteParameterSeparator()
                .Write(chunk.Start.AbsoluteIndex.ToString(CultureInfo.CurrentCulture))
                .WriteEndMethodInvocation(endLine: false)
                .WriteParameterSeparator()
                .WriteBooleanLiteral(false)
                .WriteEndMethodInvocation(false);
            }

            Context.TargetWriterName        = currentTargetWriterName;
            Context.ExpressionRenderingMode = currentRenderingMode;
        }
        public override void GenerateCode(Span target, CodeGeneratorContext context)
        {
            if (context.Host.DesignTimeMode)
            {
                return;
            }
            ExpressionRenderingMode oldMode = context.ExpressionRenderingMode;

            context.BufferStatementFragment(context.BuildCodeString(cw =>
            {
                cw.WriteParameterSeparator();
                cw.WriteStartMethodInvoke("Tuple.Create");
                cw.WriteLocationTaggedString(Prefix);
                cw.WriteParameterSeparator();
                if (ValueGenerator != null)
                {
                    cw.WriteStartMethodInvoke("Tuple.Create", "System.Object", "System.Int32");
                    context.ExpressionRenderingMode = ExpressionRenderingMode.InjectCode;
                }
                else
                {
                    cw.WriteLocationTaggedString(Value);
                    cw.WriteParameterSeparator();
                    // literal: true - This attribute value is a literal value
                    cw.WriteBooleanLiteral(true);
                    cw.WriteEndMethodInvoke();

                    // In VB, we need a line continuation
                    cw.WriteLineContinuation();
                }
            }));
            if (ValueGenerator != null)
            {
                ValueGenerator.Value.GenerateCode(target, context);
                context.FlushBufferedStatement();
                context.ExpressionRenderingMode = oldMode;
                context.AddStatement(context.BuildCodeString(cw =>
                {
                    cw.WriteParameterSeparator();
                    cw.WriteSnippet(ValueGenerator.Location.AbsoluteIndex.ToString(CultureInfo.CurrentCulture));
                    cw.WriteEndMethodInvoke();
                    cw.WriteParameterSeparator();
                    // literal: false - This attribute value is not a literal value, it is dynamically generated
                    cw.WriteBooleanLiteral(false);
                    cw.WriteEndMethodInvoke();

                    // In VB, we need a line continuation
                    cw.WriteLineContinuation();
                }));
            }
            else
            {
                context.FlushBufferedStatement();
            }
        }
예제 #4
0
        public override void GenerateStartBlockCode(Block target, CodeGeneratorContext context)
        {
            if (context.Host.DesignTimeMode)
            {
                return; // Don't generate anything!
            }

            // What kind of block is nested within
            string generatedCode;
            Block  child = target.Children.Where(n => n.IsBlock).Cast <Block>().FirstOrDefault();

            if (child != null && child.Type == BlockType.Expression)
            {
                _isExpression = true;
                generatedCode = context.BuildCodeString(
                    cw =>
                {
                    cw.WriteParameterSeparator();
                    cw.WriteStartMethodInvoke("Tuple.Create");
                    cw.WriteLocationTaggedString(Prefix);
                    cw.WriteParameterSeparator();
                    cw.WriteStartMethodInvoke("Tuple.Create", "System.Object", "System.Int32");
                }
                    );

                _oldRenderingMode = context.ExpressionRenderingMode;
                context.ExpressionRenderingMode = ExpressionRenderingMode.InjectCode;
            }
            else
            {
                generatedCode = context.BuildCodeString(
                    cw =>
                {
                    cw.WriteParameterSeparator();
                    cw.WriteStartMethodInvoke("Tuple.Create");
                    cw.WriteLocationTaggedString(Prefix);
                    cw.WriteParameterSeparator();
                    cw.WriteStartMethodInvoke("Tuple.Create", "System.Object", "System.Int32");
                    cw.WriteStartConstructor(
                        context.Host.GeneratedClassContext.TemplateTypeName
                        );
                    cw.WriteStartLambdaDelegate(ValueWriterName);
                }
                    );
            }

            context.MarkEndOfGeneratedCode();
            context.BufferStatementFragment(generatedCode);

            _oldTargetWriter         = context.TargetWriterName;
            context.TargetWriterName = ValueWriterName;
        }
        public override void GenerateStartBlockCode(Block target, CodeGeneratorContext context)
        {
            if (context.Host.DesignTimeMode)
            {
                return; // Don't generate anything!
            }

            // What kind of block is nested within
            string generatedCode;
            Block child = target.Children.Where(n => n.IsBlock).Cast<Block>().FirstOrDefault();
            if (child != null && child.Type == BlockType.Expression)
            {
                _isExpression = true;
                generatedCode = context.BuildCodeString(cw =>
                {
                    cw.WriteParameterSeparator();
                    cw.WriteStartMethodInvoke("Tuple.Create");
                    cw.WriteLocationTaggedString(Prefix);
                    cw.WriteParameterSeparator();
                    cw.WriteStartMethodInvoke("Tuple.Create", "System.Object", "System.Int32");
                });

                _oldRenderingMode = context.ExpressionRenderingMode;
                context.ExpressionRenderingMode = ExpressionRenderingMode.InjectCode;
            }
            else
            {
                generatedCode = context.BuildCodeString(cw =>
                {
                    cw.WriteParameterSeparator();
                    cw.WriteStartMethodInvoke("Tuple.Create");
                    cw.WriteLocationTaggedString(Prefix);
                    cw.WriteParameterSeparator();
                    cw.WriteStartMethodInvoke("Tuple.Create", "System.Object", "System.Int32");
                    cw.WriteStartConstructor(context.Host.GeneratedClassContext.TemplateTypeName);
                    cw.WriteStartLambdaDelegate(ValueWriterName);
                });
            }

            context.MarkEndOfGeneratedCode();
            context.BufferStatementFragment(generatedCode);

            _oldTargetWriter = context.TargetWriterName;
            context.TargetWriterName = ValueWriterName;
        }
예제 #6
0
        public override void GenerateCode(Span target, CodeGeneratorContext context)
        {
            if (context.Host.DesignTimeMode)
            {
                return;
            }

            ExpressionRenderingMode oldMode = context.GetExpressionRenderingMode();

            var sb = new StringBuilder();

            sb.Append(", Tuple.Create<string,object,bool> (");
            sb.WriteCStyleStringLiteral(Prefix.Value);
            sb.Append(", ");

            if (ValueGenerator != null)
            {
                context.SetExpressionRenderingMode(ExpressionRenderingMode.InjectCode);
            }
            else
            {
                sb.WriteCStyleStringLiteral(Value);
                sb.Append(", true)");
            }
            context.BufferStatementFragment(sb.ToString());

            if (ValueGenerator != null)
            {
                ValueGenerator.Value.GenerateCode(target, context);
                context.FlushBufferedStatement();
                context.SetExpressionRenderingMode(oldMode);
                context.AddStatement(", false)");
            }
            else
            {
                context.FlushBufferedStatement();
            }
        }
예제 #7
0
        protected override void Visit(LiteralCodeAttributeChunk chunk)
        {
            if (Context.Host.DesignTimeMode)
            {
                return; // Don't generate anything!
            }

            Writer.WriteParameterSeparator()
            .WriteStartMethodInvocation("Tuple.Create")
            .WriteLocationTaggedString(chunk.Prefix)
            .WriteParameterSeparator();

            if (chunk.Children.Count > 0 || chunk.Value == null)
            {
                Writer.WriteStartMethodInvocation("Tuple.Create", new string[] { "System.Object", "System.Int32" });

                ExpressionRenderingMode currentRenderingMode = Context.ExpressionRenderingMode;
                Context.ExpressionRenderingMode = ExpressionRenderingMode.InjectCode;

                Accept(chunk.Children);

                Context.ExpressionRenderingMode = currentRenderingMode;

                Writer.WriteParameterSeparator()
                .Write(chunk.ValueLocation.AbsoluteIndex.ToString(CultureInfo.CurrentCulture))
                .WriteEndMethodInvocation(false)
                .WriteParameterSeparator()
                .WriteBooleanLiteral(false)
                .WriteEndMethodInvocation(false);
            }
            else
            {
                Writer.WriteLocationTaggedString(chunk.Value)
                .WriteParameterSeparator()
                .WriteBooleanLiteral(true)
                .WriteEndMethodInvocation(false);
            }
        }
예제 #8
0
        public override void GenerateStartBlockCode(Block target, CodeGeneratorContext context)
        {
            if (context.Host.DesignTimeMode)
            {
                return;
            }

            Block child = target.Children.Where(n => n.IsBlock).Cast <Block> ().FirstOrDefault();

            isExpression = child != null && child.Type == BlockType.Expression;

            var sb = new StringBuilder();

            sb.Append(", Tuple.Create<string,object,bool> (");
            sb.WriteCStyleStringLiteral(Prefix.Value);
            sb.Append(", ");

            if (isExpression)
            {
                oldRenderingMode = context.GetExpressionRenderingMode();
                context.SetExpressionRenderingMode(ExpressionRenderingMode.InjectCode);
            }
            else
            {
                sb.AppendFormat(
                    "new {0} ({1} => {{",
                    context.Host.GeneratedClassContext.TemplateTypeName,
                    ValueWriterName);
            }

            context.MarkEndOfGeneratedCode();
            context.BufferStatementFragment(sb.ToString());

            oldTargetWriter          = context.TargetWriterName;
            context.TargetWriterName = ValueWriterName;
        }
		public static void SetExpressionRenderingMode ( this CodeGeneratorContext context, ExpressionRenderingMode mode)
		{
			context.GetType ().InvokeMember (
				"ExpressionRenderingMode",
				BindingFlags.SetProperty | BindingFlags.NonPublic | BindingFlags.Instance,
				null,
				context,
				new object[] { mode }
			);
		}
예제 #10
0
 public static void SetExpressionRenderingMode(this CodeGeneratorContext context, ExpressionRenderingMode mode)
 {
     context.GetType().InvokeMember(
         "ExpressionRenderingMode",
         BindingFlags.SetProperty | BindingFlags.NonPublic | BindingFlags.Instance,
         null,
         context,
         new object[] { mode }
         );
 }