本文整理汇总了C#中System.Web.Razor.Generator.CodeGeneratorContext.AddStatement方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGeneratorContext.AddStatement方法的具体用法?C# CodeGeneratorContext.AddStatement怎么用?C# CodeGeneratorContext.AddStatement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Razor.Generator.CodeGeneratorContext
的用法示例。
在下文中一共展示了CodeGeneratorContext.AddStatement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateStartBlockCode
public override void GenerateStartBlockCode(Block target, CodeGeneratorContext context)
{
if (context.Host.DesignTimeMode)
{
return; // Don't generate anything!
}
context.FlushBufferedStatement();
context.AddStatement(context.BuildCodeString(cw =>
{
if (!String.IsNullOrEmpty(context.TargetWriterName))
{
cw.WriteStartMethodInvoke(context.Host.GeneratedClassContext.WriteAttributeToMethodName);
cw.WriteSnippet(context.TargetWriterName);
cw.WriteParameterSeparator();
}
else
{
cw.WriteStartMethodInvoke(context.Host.GeneratedClassContext.WriteAttributeMethodName);
}
cw.WriteStringLiteral(Name);
cw.WriteParameterSeparator();
cw.WriteLocationTaggedString(Prefix);
cw.WriteParameterSeparator();
cw.WriteLocationTaggedString(Suffix);
// In VB, we need a line continuation
cw.WriteLineContinuation();
}));
}
示例2: GenerateCode
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 ();
}
}
示例3: GenerateStartBlockCode
public override void GenerateStartBlockCode (Block target, CodeGeneratorContext context)
{
if (context.Host.DesignTimeMode)
return;
context.FlushBufferedStatement();
var sb = new StringBuilder ();
if (!string.IsNullOrEmpty (context.TargetWriterName)) {
sb.AppendFormat (
"{0} ({1}, ",
context.Host.GeneratedClassContext.WriteAttributeToMethodName,
context.TargetWriterName
);
} else {
sb.AppendFormat (
"{0} (",
context.Host.GeneratedClassContext.WriteAttributeMethodName
);
}
sb.WriteCStyleStringLiteral (Name);
sb.Append (", ");
sb.WriteCStyleStringLiteral (Prefix);
sb.Append (", ");
sb.WriteCStyleStringLiteral (Suffix);
context.AddStatement (sb.ToString ());
}
示例4: GenerateCode
public override void GenerateCode(Span target, CodeGeneratorContext context)
{
context.FlushBufferedStatement();
string generatedCode = context.BuildCodeString(cw =>
{
cw.WriteSnippet(target.Content);
});
int startGeneratedCode = target.Start.CharacterIndex;
generatedCode = Pad(generatedCode, target);
// Is this the span immediately following "@"?
if (context.Host.DesignTimeMode &&
!String.IsNullOrEmpty(generatedCode) &&
Char.IsWhiteSpace(generatedCode[0]) &&
target.Previous != null &&
target.Previous.Kind == SpanKind.Transition &&
String.Equals(target.Previous.Content, SyntaxConstants.TransitionString))
{
generatedCode = generatedCode.Substring(1);
startGeneratedCode--;
}
context.AddStatement(
generatedCode,
context.GenerateLinePragma(target, startGeneratedCode));
}
示例5: GenerateEndBlockCode
public override void GenerateEndBlockCode (Block target, CodeGeneratorContext context)
{
if (context.Host.DesignTimeMode)
return;
context.FlushBufferedStatement ();
context.AddStatement (");");
}
示例6: GenerateEndBlockCode
public override void GenerateEndBlockCode(Block target, CodeGeneratorContext context)
{
string startBlock = context.BuildCodeString(cw =>
{
cw.WriteEndLambdaDelegate();
cw.WriteEndMethodInvoke();
cw.WriteEndStatement();
});
context.AddStatement(startBlock);
}
示例7: GenerateStartBlockCode
public override void GenerateStartBlockCode(Block target, CodeGeneratorContext context)
{
string startBlock = context.BuildCodeString(cw =>
{
cw.WriteStartMethodInvoke(context.Host.GeneratedClassContext.DefineSectionMethodName);
cw.WriteStringLiteral(SectionName);
cw.WriteParameterSeparator();
cw.WriteStartLambdaDelegate();
});
context.AddStatement(startBlock);
}
示例8: GenerateCode
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();
}
}
示例9: GenerateCode
public override void GenerateCode(Span target, CodeGeneratorContext context)
{
// Build the string
string code = Prefix + target.Content + ";";
// Calculate the line pragma including information about where the user-specified code starts and ends (for editors)
CodeLinePragma pragma = context.GenerateLinePragma(target, Prefix.Length, target.Content.Length);
// Add the statement
context.AddStatement(code, pragma);
}
示例10: GenerateEndBlockCode
public override void GenerateEndBlockCode(Block target, CodeGeneratorContext context)
{
if (context.Host.DesignTimeMode)
{
return; // Don't generate anything!
}
context.FlushBufferedStatement();
context.AddStatement(context.BuildCodeString(cw =>
{
cw.WriteEndMethodInvoke();
cw.WriteEndStatement();
}));
}
示例11: GenerateCode
public override void GenerateCode(Span target, CodeGeneratorContext context)
{
context.FlushBufferedStatement();
string generatedCode = context.BuildCodeString(cw =>
{
cw.WriteSnippet(target.Content);
});
int startGeneratedCode = target.Start.CharacterIndex;
int paddingCharCount;
generatedCode = CodeGeneratorPaddingHelper.PadStatement(context.Host, generatedCode, target, ref startGeneratedCode, out paddingCharCount);
context.AddStatement(
generatedCode,
context.GenerateLinePragma(target, paddingCharCount));
}
示例12: GenerateCode
public override void GenerateCode(Span target, CodeGeneratorContext context)
{
if (!context.Host.DesignTimeMode && String.IsNullOrEmpty(target.Content))
{
return;
}
if (context.Host.EnableInstrumentation)
{
context.AddContextCall(target, context.Host.GeneratedClassContext.BeginContextMethodName, isLiteral: true);
}
if (!String.IsNullOrEmpty(target.Content) && !context.Host.DesignTimeMode)
{
string code = context.BuildCodeString(cw =>
{
if (!String.IsNullOrEmpty(context.TargetWriterName))
{
cw.WriteStartMethodInvoke(context.Host.GeneratedClassContext.WriteLiteralToMethodName);
cw.WriteSnippet(context.TargetWriterName);
cw.WriteParameterSeparator();
}
else
{
cw.WriteStartMethodInvoke(context.Host.GeneratedClassContext.WriteLiteralMethodName);
}
cw.WriteStringLiteral(target.Content);
cw.WriteEndMethodInvoke();
cw.WriteEndStatement();
});
context.AddStatement(code);
}
if (context.Host.EnableInstrumentation)
{
context.AddContextCall(target, context.Host.GeneratedClassContext.EndContextMethodName, isLiteral: true);
}
}
示例13: GenerateEndBlockCode
public override void GenerateEndBlockCode (Block target, CodeGeneratorContext context)
{
if (context.Host.DesignTimeMode)
return;
var sb = new StringBuilder ();
if (isExpression) {
sb.Append (", false)");
context.SetExpressionRenderingMode (oldRenderingMode);
} else {
sb.Append ("}), false)");
}
context.AddStatement (sb.ToString ());
context.TargetWriterName = oldTargetWriter;
}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:16,代码来源:PreprocessedDynamicAttributeBlockCodeGenerator.cs
示例14: GenerateEndBlockCode
public override void GenerateEndBlockCode(Block target, CodeGeneratorContext context)
{
if (context.Host.DesignTimeMode)
{
return; // Don't generate anything!
}
string generatedCode;
if (_isExpression)
{
generatedCode = context.BuildCodeString(cw =>
{
cw.WriteParameterSeparator();
cw.WriteSnippet(ValueStart.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();
cw.WriteLineContinuation();
});
context.ExpressionRenderingMode = _oldRenderingMode;
}
else
{
generatedCode = context.BuildCodeString(cw =>
{
cw.WriteEndLambdaDelegate();
cw.WriteEndConstructor();
cw.WriteParameterSeparator();
cw.WriteSnippet(ValueStart.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();
cw.WriteLineContinuation();
});
}
context.AddStatement(generatedCode);
context.TargetWriterName = _oldTargetWriter;
}
示例15: GenerateCode
public override void GenerateCode(Span target, CodeGeneratorContext context)
{
// Check if the host supports it
if (String.IsNullOrEmpty(context.Host.GeneratedClassContext.ResolveUrlMethodName))
{
// Nope, just use the default MarkupCodeGenerator behavior
new MarkupCodeGenerator().GenerateCode(target, context);
return;
}
if (!context.Host.DesignTimeMode && String.IsNullOrEmpty(target.Content))
{
return;
}
if (context.Host.EnableInstrumentation && context.ExpressionRenderingMode == ExpressionRenderingMode.WriteToOutput)
{
// Add a non-literal context call (non-literal because the expanded URL will not match the source character-by-character)
context.AddContextCall(target, context.Host.GeneratedClassContext.BeginContextMethodName, isLiteral: false);
}
if (!String.IsNullOrEmpty(target.Content) && !context.Host.DesignTimeMode)
{
string code = context.BuildCodeString(cw =>
{
if (context.ExpressionRenderingMode == ExpressionRenderingMode.WriteToOutput)
{
if (!String.IsNullOrEmpty(context.TargetWriterName))
{
cw.WriteStartMethodInvoke(context.Host.GeneratedClassContext.WriteLiteralToMethodName);
cw.WriteSnippet(context.TargetWriterName);
cw.WriteParameterSeparator();
}
else
{
cw.WriteStartMethodInvoke(context.Host.GeneratedClassContext.WriteLiteralMethodName);
}
}
cw.WriteStartMethodInvoke(context.Host.GeneratedClassContext.ResolveUrlMethodName);
cw.WriteStringLiteral(target.Content);
cw.WriteEndMethodInvoke();
if (context.ExpressionRenderingMode == ExpressionRenderingMode.WriteToOutput)
{
cw.WriteEndMethodInvoke();
cw.WriteEndStatement();
}
else
{
cw.WriteLineContinuation();
}
});
if (context.ExpressionRenderingMode == ExpressionRenderingMode.WriteToOutput)
{
context.AddStatement(code);
}
else
{
context.BufferStatementFragment(code);
}
}
if (context.Host.EnableInstrumentation && context.ExpressionRenderingMode == ExpressionRenderingMode.WriteToOutput)
{
context.AddContextCall(target, context.Host.GeneratedClassContext.EndContextMethodName, isLiteral: false);
}
}