本文整理汇总了C#中Microsoft.AspNet.Razor.Parser.SyntaxTree.Span类的典型用法代码示例。如果您正苦于以下问题:C# Span类的具体用法?C# Span怎么用?C# Span使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Span类属于Microsoft.AspNet.Razor.Parser.SyntaxTree命名空间,在下文中一共展示了Span类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ParseModelKeyword_HandlesSingleInstance
public void ParseModelKeyword_HandlesSingleInstance()
{
// Arrange
var document = "@model Foo";
var factory = SpanFactory.CreateCsHtml();
var errors = new List<RazorError>();
var expectedSpans = new Span[]
{
factory.EmptyHtml(),
factory.CodeTransition(SyntaxConstants.TransitionString)
.Accepts(AcceptedCharacters.None),
factory.MetaCode("model ")
.Accepts(AcceptedCharacters.None),
factory.Code(" Foo")
.As(new ModelChunkGenerator("Foo"))
.Accepts(AcceptedCharacters.AnyExceptNewline),
factory.EmptyHtml()
};
// Act
var spans = ParseDocument(document, errors);
// Assert
Assert.Equal(expectedSpans, spans);
Assert.Empty(errors);
}
开发者ID:huoxudong125,项目名称:Mvc,代码行数:26,代码来源:MvcCSharpRazorCodeParserTest.cs
示例2: CalculatePadding
internal int CalculatePadding(Span target, int generatedStart)
{
if (target == null)
{
throw new ArgumentNullException("target");
}
int padding;
padding = CollectSpacesAndTabs(target, _host.TabSize) - generatedStart;
// if we add generated text that is longer than the padding we wanted to insert we have no recourse and we have to skip padding
// example:
// Razor code at column zero: @somecode()
// Generated code will be:
// In design time: __o = somecode();
// In Run time: Write(somecode());
//
// In both cases the padding would have been 1 space to remote the space the @ symbol takes, which will be smaller than the 6
// chars the hidden generated code takes.
if (padding < 0)
{
padding = 0;
}
return padding;
}
开发者ID:hamaky,项目名称:Razor,代码行数:27,代码来源:CSharpPaddingBuilder.cs
示例3: OwnsChange
public virtual bool OwnsChange(Span target, TextChange change)
{
int end = target.Start.AbsoluteIndex + target.Length;
int changeOldEnd = change.OldPosition + change.OldLength;
return change.OldPosition >= target.Start.AbsoluteIndex &&
(changeOldEnd < end || (changeOldEnd == end && AcceptedCharacters != AcceptedCharacters.None));
}
开发者ID:KennyBu,项目名称:Razor,代码行数:7,代码来源:SpanEditHandler.cs
示例4: VisitSpan
public override void VisitSpan(Span span)
{
// We're only interested in spans with an AddOrRemoveTagHelperChunkGenerator.
if (span.ChunkGenerator is AddOrRemoveTagHelperChunkGenerator)
{
var chunkGenerator = (AddOrRemoveTagHelperChunkGenerator)span.ChunkGenerator;
var directive =
chunkGenerator.RemoveTagHelperDescriptors ?
TagHelperDirectiveType.RemoveTagHelper :
TagHelperDirectiveType.AddTagHelper;
var directiveDescriptor = new TagHelperDirectiveDescriptor(
chunkGenerator.LookupText,
span.Start,
directive);
_directiveDescriptors.Add(directiveDescriptor);
}
else if (span.ChunkGenerator is TagHelperPrefixDirectiveChunkGenerator)
{
var chunkGenerator = (TagHelperPrefixDirectiveChunkGenerator)span.ChunkGenerator;
var directiveDescriptor = new TagHelperDirectiveDescriptor(
chunkGenerator.Prefix,
span.Start,
TagHelperDirectiveType.TagHelperPrefix);
_directiveDescriptors.Add(directiveDescriptor);
}
}
开发者ID:jgglg,项目名称:Razor,代码行数:32,代码来源:TagHelperDirectiveSpanVisitor.cs
示例5: PadStatement
// Special case for statement padding to account for brace positioning in the editor.
public static string PadStatement(RazorEngineHost host, string code, Span target, ref int startGeneratedCode, out int paddingCharCount)
{
if (host == null)
{
throw new ArgumentNullException("host");
}
if (target == null)
{
throw new ArgumentNullException("target");
}
// We are passing 0 rather than startgeneratedcode intentionally (keeping v2 behavior).
int padding = CalculatePadding(host, target, 0);
// We treat statement padding specially so for brace positioning, so that in the following example:
// @if (foo > 0)
// {
// }
//
// the braces shows up under the @ rather than under the if.
if (host.DesignTimeMode &&
padding > 0 &&
target.Previous.Kind == SpanKind.Transition && // target.Previous is guaranteed to be none null if you got any padding.
String.Equals(target.Previous.Content, SyntaxConstants.TransitionString))
{
padding--;
startGeneratedCode--;
}
string generatedCode = PadInternal(host, code, padding, out paddingCharCount);
return generatedCode;
}
开发者ID:KennyBu,项目名称:Razor,代码行数:35,代码来源:CodeGeneratorPaddingHelper.cs
示例6: ParseModelKeyword_InfersBaseType_FromModelName
public void ParseModelKeyword_InfersBaseType_FromModelName(string modelName,
string expectedModel)
{
// Arrange
var documentContent = "@model " + modelName + Environment.NewLine + "Bar";
var factory = SpanFactory.CreateCsHtml();
var errors = new List<RazorError>();
var expectedSpans = new Span[]
{
factory.EmptyHtml(),
factory.CodeTransition(SyntaxConstants.TransitionString)
.Accepts(AcceptedCharacters.None),
factory.MetaCode("model ")
.Accepts(AcceptedCharacters.None),
factory.Code(modelName + Environment.NewLine)
.As(new ModelChunkGenerator("RazorView", expectedModel))
.Accepts(AcceptedCharacters.AnyExceptNewline),
factory.Markup("Bar")
.With(new MarkupChunkGenerator())
};
// Act
var spans = ParseDocument(documentContent, errors);
// Assert
Assert.Equal(expectedSpans, spans);
Assert.Empty(errors);
}
开发者ID:notami18,项目名称:Mvc,代码行数:28,代码来源:MvcCSharpRazorCodeParserTest.cs
示例7: 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);
}
开发者ID:KennyBu,项目名称:Razor,代码行数:25,代码来源:AddImportCodeGenerator.cs
示例8: GenerateCode
public override void GenerateCode(Span target, CodeGeneratorContext context)
{
if (Name == SyntaxConstants.CSharp.SessionStateKeyword)
{
context.CodeTreeBuilder.AddSessionStateChunk(Value, target);
}
}
开发者ID:hamaky,项目名称:Razor,代码行数:7,代码来源:RazorDirectiveAttributeCodeGenerator.cs
示例9: BuildStatementPadding
// Special case for statement padding to account for brace positioning in the editor.
public string BuildStatementPadding(Span target)
{
if (target == null)
{
throw new ArgumentNullException("target");
}
int padding = CalculatePadding(target, generatedStart: 0);
// We treat statement padding specially so for brace positioning, so that in the following example:
// @if (foo > 0)
// {
// }
//
// the braces shows up under the @ rather than under the if.
if (_host.DesignTimeMode &&
padding > 0 &&
target.Previous.Kind == SpanKind.Transition && // target.Previous is guaranteed to not be null if you have padding.
String.Equals(target.Previous.Content, SyntaxConstants.TransitionString, StringComparison.Ordinal))
{
padding--;
}
string generatedCode = BuildPaddingInternal(padding);
return generatedCode;
}
开发者ID:hamaky,项目名称:Razor,代码行数:28,代码来源:CSharpPaddingBuilder.cs
示例10: SpanBuilder
public SpanBuilder(Span original)
{
Kind = original.Kind;
_symbols = new List<ISymbol>(original.Symbols);
EditHandler = original.EditHandler;
CodeGenerator = original.CodeGenerator;
Start = original.Start;
}
开发者ID:KennyBu,项目名称:Razor,代码行数:8,代码来源:SpanBuilder.cs
示例11: GenerateCode
public override void GenerateCode(Span target, CodeGeneratorContext context)
{
var attributeType = new CodeTypeReference(typeof(RazorDirectiveAttribute));
var attributeDeclaration = new CodeAttributeDeclaration(
attributeType,
new CodeAttributeArgument(new CodePrimitiveExpression(Name)),
new CodeAttributeArgument(new CodePrimitiveExpression(Value)));
context.GeneratedClass.CustomAttributes.Add(attributeDeclaration);
}
开发者ID:KennyBu,项目名称:Razor,代码行数:9,代码来源:RazorDirectiveAttributeCodeGenerator.cs
示例12: GenerateCode
public override void GenerateCode(Span target, CodeGeneratorContext context)
{
if (!context.Host.DesignTimeMode && !String.IsNullOrEmpty(context.Host.GeneratedClassContext.LayoutPropertyName))
{
context.TargetMethod.Statements.Add(
new CodeAssignStatement(
new CodePropertyReferenceExpression(null, context.Host.GeneratedClassContext.LayoutPropertyName),
new CodePrimitiveExpression(LayoutPath)));
}
}
开发者ID:KennyBu,项目名称:Razor,代码行数:10,代码来源:SetLayoutCodeGenerator.cs
示例13: CalculatePaddingForEmptySpanReturnsZero
public void CalculatePaddingForEmptySpanReturnsZero()
{
RazorEngineHost host = CreateHost(designTime: true);
Span span = new Span(new SpanBuilder());
int padding = CodeGeneratorPaddingHelper.CalculatePadding(host, span, 0);
Assert.Equal(0, padding);
}
开发者ID:KennyBu,项目名称:Razor,代码行数:10,代码来源:PaddingTest.cs
示例14: GenerateChunk
public override void GenerateChunk(Span target, ChunkGeneratorContext context)
{
var ns = Namespace;
if (!string.IsNullOrEmpty(ns) && char.IsWhiteSpace(ns[0]))
{
ns = ns.Substring(1);
}
context.ChunkTreeBuilder.AddUsingChunk(ns, target);
}
开发者ID:huoxudong125,项目名称:Razor,代码行数:11,代码来源:AddImportChunkGenerator.cs
示例15: BuildExpressionPadding
public string BuildExpressionPadding(Span target, int generatedStart)
{
if (target == null)
{
throw new ArgumentNullException(nameof(target));
}
var padding = CalculatePadding(target, generatedStart);
return BuildPaddingInternal(padding);
}
开发者ID:huoxudong125,项目名称:Razor,代码行数:11,代码来源:CSharpPaddingBuilder.cs
示例16: 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();
}
}
开发者ID:KennyBu,项目名称:Razor,代码行数:54,代码来源:LiteralAttributeCodeGenerator.cs
示例17: CalculateStart
internal void CalculateStart(Span prev)
{
if (prev == null)
{
Start = SourceLocation.Zero;
}
else
{
Start = new SourceLocationTracker(prev.Start).UpdateLocation(prev.Content).CurrentLocation;
}
}
开发者ID:KennyBu,项目名称:Razor,代码行数:11,代码来源:RawTextSymbol.cs
示例18: CanAcceptChange
protected override PartialParseResult CanAcceptChange(Span target, TextChange normalizedChange)
{
if (((AutoCompleteAtEndOfSpan && IsAtEndOfSpan(target, normalizedChange)) || IsAtEndOfFirstLine(target, normalizedChange)) &&
normalizedChange.IsInsert &&
ParserHelpers.IsNewLine(normalizedChange.NewText) &&
AutoCompleteString != null)
{
return PartialParseResult.Rejected | PartialParseResult.AutoCompleteBlock;
}
return PartialParseResult.Rejected;
}
开发者ID:rohitpoudel,项目名称:Razor,代码行数:11,代码来源:AutoCompleteEditHandler.cs
示例19: GenerateCode
public override void GenerateCode(Span target, CodeGeneratorContext context)
{
string ns = Namespace;
if (!String.IsNullOrEmpty(ns) && Char.IsWhiteSpace(ns[0]))
{
ns = ns.Substring(1);
}
context.CodeTreeBuilder.AddUsingChunk(ns, target);
}
开发者ID:hamaky,项目名称:Razor,代码行数:11,代码来源:AddImportCodeGenerator.cs
示例20: GenerateChunk
/// <summary>
/// Generates <see cref="AddTagHelperChunk"/>s if <see cref="RemoveTagHelperDescriptors"/> is
/// <c>true</c>, otherwise <see cref="RemoveTagHelperChunk"/>s are generated.
/// </summary>
/// <param name="target">
/// The <see cref="Span"/> responsible for this <see cref="AddOrRemoveTagHelperChunkGenerator"/>.
/// </param>
/// <param name="context">A <see cref="ChunkGeneratorContext"/> instance that contains information about
/// the current chunk generation process.</param>
public override void GenerateChunk(Span target, ChunkGeneratorContext context)
{
if (RemoveTagHelperDescriptors)
{
context.ChunkTreeBuilder.AddRemoveTagHelperChunk(LookupText, target);
}
else
{
context.ChunkTreeBuilder.AddAddTagHelperChunk(LookupText, target);
}
}
开发者ID:huoxudong125,项目名称:Razor,代码行数:20,代码来源:AddOrRemoveTagHelperChunkGenerator.cs
注:本文中的Microsoft.AspNet.Razor.Parser.SyntaxTree.Span类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论