本文整理汇总了C#中System.Web.Razor.Generator.CodeGeneratorContext.GenerateLinePragma方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGeneratorContext.GenerateLinePragma方法的具体用法?C# CodeGeneratorContext.GenerateLinePragma怎么用?C# CodeGeneratorContext.GenerateLinePragma使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Razor.Generator.CodeGeneratorContext
的用法示例。
在下文中一共展示了CodeGeneratorContext.GenerateLinePragma方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateCode
public override void GenerateCode(Span target, CodeGeneratorContext context)
{
// Try to find the namespace in the existing imports
string ns = Namespace;
if (!String.IsNullOrEmpty(ns) && Char.IsWhiteSpace(ns[0]))
{
ns = ns.Substring(1);
}
CodeNamespaceImport import = context.Namespace
.Imports
.OfType<CodeNamespaceImport>()
.Where(i => String.Equals(i.Namespace, ns.Trim(), StringComparison.Ordinal))
.FirstOrDefault();
if (import == null)
{
// It doesn't exist, create it
import = new CodeNamespaceImport(ns);
context.Namespace.Imports.Add(import);
}
// Attach our info to the existing/new import.
import.LinePragma = context.GenerateLinePragma(target);
}
示例2: GenerateStartBlockCode
public override void GenerateStartBlockCode(Block target, CodeGeneratorContext context)
{
_writer = context.CreateCodeWriter();
string prefix = context.BuildCodeString(
cw => cw.WriteHelperHeaderPrefix(context.Host.GeneratedClassContext.TemplateTypeName, context.Host.StaticHelpers));
_writer.WriteLinePragma(
context.GenerateLinePragma(Signature.Location, prefix.Length, Signature.Value.Length));
_writer.WriteSnippet(prefix);
_writer.WriteSnippet(Signature);
if (HeaderComplete)
{
_writer.WriteHelperHeaderSuffix(context.Host.GeneratedClassContext.TemplateTypeName);
}
_writer.WriteLinePragma(null);
if (HeaderComplete)
{
_writer.WriteReturn();
_writer.WriteStartConstructor(context.Host.GeneratedClassContext.TemplateTypeName);
_writer.WriteStartLambdaDelegate(HelperWriterName);
}
_statementCollectorToken = context.ChangeStatementCollector(AddStatementToHelper);
_oldWriter = context.TargetWriterName;
context.TargetWriterName = HelperWriterName;
}
示例3: 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));
}
示例4: 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);
}
示例5: GenerateCode
public override void GenerateCode(Span target, CodeGeneratorContext context)
{
string generatedCode = context.BuildCodeString(cw =>
{
cw.WriteSnippet(target.Content);
});
context.GeneratedClass.Members.Add(
new CodeSnippetTypeMember(Pad(generatedCode, target))
{
LinePragma = context.GenerateLinePragma(target, target.Start.CharacterIndex)
});
}
示例6: GenerateCode
public override void GenerateCode(Span target, CodeGeneratorContext context)
{
context.GeneratedClass.BaseTypes.Clear();
context.GeneratedClass.BaseTypes.Add(new CodeTypeReference(ResolveType(context)));
#region Work Around
if (!(context.Host.CodeLanguage is VBRazorCodeLanguage))
context.GeneratedClass.LinePragma = context.GenerateLinePragma(target, CalculateSpanPadding(target,0));
//else
// exclude VBRazorCodeLanguage
// with VB I found a problem with the #End ExternalSource directive rendered at the GeneratedClass's end while it should not be rendered
// this only effects the compile error report
#endregion
}
示例7: 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));
}
示例8: GenerateCode
public override void GenerateCode(Span target, CodeGeneratorContext context)
{
string generatedCode = context.BuildCodeString(cw =>
{
cw.WriteSnippet(target.Content);
});
int paddingCharCount;
string paddedCode = CodeGeneratorPaddingHelper.Pad(context.Host, generatedCode, target, out paddingCharCount);
Contract.Assert(paddingCharCount > 0);
context.GeneratedClass.Members.Add(
new CodeSnippetTypeMember(paddedCode)
{
LinePragma = context.GenerateLinePragma(target, paddingCharCount)
});
}
示例9: GenerateEndBlockCode
public override void GenerateEndBlockCode(Block target, CodeGeneratorContext context)
{
_statementCollectorToken.Dispose();
if (HeaderComplete)
{
_writer.WriteEndLambdaDelegate();
_writer.WriteEndConstructor();
_writer.WriteEndStatement();
}
if (Footer != null && !String.IsNullOrEmpty(Footer.Value))
{
_writer.WriteLinePragma(
context.GenerateLinePragma(Footer.Location, 0, Footer.Value.Length));
_writer.WriteSnippet(Footer);
_writer.WriteLinePragma();
}
_writer.WriteHelperTrailer();
context.GeneratedClass.Members.Add(new CodeSnippetTypeMember(_writer.Content));
context.TargetWriterName = _oldWriter;
}
示例10: GenerateCode
public override void GenerateCode(Span target, CodeGeneratorContext context)
{
context.GeneratedClass.BaseTypes.Clear();
context.GeneratedClass.BaseTypes.Add(new CodeTypeReference(ResolveType(context, BaseType.Trim())));
if (context.Host.DesignTimeMode)
{
int generatedCodeStart = 0;
string code = context.BuildCodeString(cw =>
{
generatedCodeStart = cw.WriteVariableDeclaration(target.Content, "__inheritsHelper", null);
cw.WriteEndStatement();
});
int paddingCharCount;
CodeSnippetStatement stmt = new CodeSnippetStatement(
CodeGeneratorPaddingHelper.Pad(context.Host, code, target, generatedCodeStart, out paddingCharCount))
{
LinePragma = context.GenerateLinePragma(target, generatedCodeStart + paddingCharCount)
};
context.AddDesignTimeHelperStatement(stmt);
}
}