本文整理汇总了C#中System.Web.Razor.Generator.CodeGeneratorContext.AddContextCall方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGeneratorContext.AddContextCall方法的具体用法?C# CodeGeneratorContext.AddContextCall怎么用?C# CodeGeneratorContext.AddContextCall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Razor.Generator.CodeGeneratorContext
的用法示例。
在下文中一共展示了CodeGeneratorContext.AddContextCall方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateEndBlockCode
public override void GenerateEndBlockCode(Block target, CodeGeneratorContext context)
{
string endBlock = context.BuildCodeString(cw =>
{
if (context.ExpressionRenderingMode == ExpressionRenderingMode.WriteToOutput)
{
if (!context.Host.DesignTimeMode)
{
cw.WriteEndMethodInvoke();
}
cw.WriteEndStatement();
}
else
{
cw.WriteLineContinuation();
}
});
context.MarkEndOfGeneratedCode();
context.BufferStatementFragment(endBlock);
context.FlushBufferedStatement();
if (context.Host.EnableInstrumentation && context.ExpressionRenderingMode == ExpressionRenderingMode.WriteToOutput)
{
Span contentSpan = target.Children
.OfType<Span>()
.Where(s => s.Kind == SpanKind.Code || s.Kind == SpanKind.Markup)
.FirstOrDefault();
if (contentSpan != null)
{
context.AddContextCall(contentSpan, context.Host.GeneratedClassContext.EndContextMethodName, false);
}
}
}
示例2: 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);
}
}
示例3: GenerateStartBlockCode
public override void GenerateStartBlockCode(Block target, CodeGeneratorContext context)
{
if (context.Host.EnableInstrumentation && context.ExpressionRenderingMode == ExpressionRenderingMode.WriteToOutput)
{
Span contentSpan = target.Children
.OfType<Span>()
.Where(s => s.Kind == SpanKind.Code || s.Kind == SpanKind.Markup)
.FirstOrDefault();
if (contentSpan != null)
{
context.AddContextCall(contentSpan, context.Host.GeneratedClassContext.BeginContextMethodName, false);
}
}
string writeInvocation = context.BuildCodeString(cw =>
{
if (context.Host.DesignTimeMode)
{
context.EnsureExpressionHelperVariable();
cw.WriteStartAssignment("__o");
}
else if (context.ExpressionRenderingMode == ExpressionRenderingMode.WriteToOutput)
{
if (!String.IsNullOrEmpty(context.TargetWriterName))
{
cw.WriteStartMethodInvoke(context.Host.GeneratedClassContext.WriteToMethodName);
cw.WriteSnippet(context.TargetWriterName);
cw.WriteParameterSeparator();
}
else
{
cw.WriteStartMethodInvoke(context.Host.GeneratedClassContext.WriteMethodName);
}
}
});
context.BufferStatementFragment(writeInvocation);
context.MarkStartOfGeneratedCode();
}
示例4: 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);
}
}