本文整理汇总了C#中System.Web.Razor.Text.TextChange类的典型用法代码示例。如果您正苦于以下问题:C# TextChange类的具体用法?C# TextChange怎么用?C# TextChange使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TextChange类属于System.Web.Razor.Text命名空间,在下文中一共展示了TextChange类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteDebugTree
internal static void WriteDebugTree(string sourceFile, Block document, PartialParseResult result, TextChange change, RazorEditorParser parser, bool treeStructureChanged)
{
if (!OutputDebuggingEnabled)
{
return;
}
RunTask(() =>
{
string outputFileName = Normalize(sourceFile) + "_tree";
string outputPath = Path.Combine(Path.GetDirectoryName(sourceFile), outputFileName);
var treeBuilder = new StringBuilder();
WriteTree(document, treeBuilder);
treeBuilder.AppendLine();
treeBuilder.AppendFormat(CultureInfo.CurrentCulture, "Last Change: {0}", change);
treeBuilder.AppendLine();
treeBuilder.AppendFormat(CultureInfo.CurrentCulture, "Normalized To: {0}", change.Normalize());
treeBuilder.AppendLine();
treeBuilder.AppendFormat(CultureInfo.CurrentCulture, "Partial Parse Result: {0}", result);
treeBuilder.AppendLine();
if (result.HasFlag(PartialParseResult.Rejected))
{
treeBuilder.AppendFormat(CultureInfo.CurrentCulture, "Tree Structure Changed: {0}", treeStructureChanged);
treeBuilder.AppendLine();
}
if (result.HasFlag(PartialParseResult.AutoCompleteBlock))
{
treeBuilder.AppendFormat(CultureInfo.CurrentCulture, "Auto Complete Insert String: \"{0}\"", parser.GetAutoCompleteString());
treeBuilder.AppendLine();
}
File.WriteAllText(outputPath, treeBuilder.ToString());
});
}
示例2: BackgroundParseTask
private BackgroundParseTask(RazorTemplateEngine engine, string sourceFileName, TextChange change)
{
Change = change;
Engine = engine;
SourceFileName = sourceFileName;
InnerTask = new Task(() => Run(_cancelSource.Token), _cancelSource.Token);
}
示例3: CheckForStructureChangesStartsFullReparseIfChangeOverlapsMultipleSpans
public void CheckForStructureChangesStartsFullReparseIfChangeOverlapsMultipleSpans() {
// Arrange
RazorEditorParser parser = new RazorEditorParser(CreateHost(), TestLinePragmaFileName);
ITextBuffer original = new StringTextBuffer("Foo @bar Baz");
ITextBuffer changed = new StringTextBuffer("Foo @bap Daz");
TextChange change = new TextChange(7, 3, original, 3, changed);
ManualResetEventSlim parseComplete = new ManualResetEventSlim();
int parseCount = 0;
parser.DocumentParseComplete += (sender, args) => {
Interlocked.Increment(ref parseCount);
parseComplete.Set();
};
Assert.AreEqual(PartialParseResult.Rejected, parser.CheckForStructureChanges(new TextChange(0, 0, new StringTextBuffer(String.Empty), 12, original)));
MiscUtils.DoWithTimeoutIfNotDebugging(parseComplete.Wait); // Wait for the parse to finish
parseComplete.Reset();
// Act
PartialParseResult result = parser.CheckForStructureChanges(change);
// Assert
Assert.AreEqual(PartialParseResult.Rejected, result);
MiscUtils.DoWithTimeoutIfNotDebugging(parseComplete.Wait);
Assert.AreEqual(2, parseCount);
}
示例4: 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));
}
示例5: OwnsChangeReturnsFalseIfChangeIsReplacementOrDeleteAtSpanEnd
public void OwnsChangeReturnsFalseIfChangeIsReplacementOrDeleteAtSpanEnd() {
// Arrange
Span span = new CodeSpan(new SourceLocation(42, 0, 42), "FooBarBaz");
TextChange change = new TextChange(51, 2, new StringTextBuffer("BooBarBaz"), 3, new StringTextBuffer("Foo"));
// Act/Assert
Assert.IsFalse(span.OwnsChange(change));
}
示例6: OwnsChangeReturnsTrueIfChangeIsInsertionAtSpanEndAndCanGrowIsTrue
public void OwnsChangeReturnsTrueIfChangeIsInsertionAtSpanEndAndCanGrowIsTrue() {
// Arrange
Span span = new CodeSpan(new SourceLocation(42, 0, 42), "FooBarBaz");
TextChange change = new TextChange(51, 0, new StringTextBuffer("BooBarBaz"), 3, new StringTextBuffer("Foo"));
// Act/Assert
Assert.IsTrue(span.OwnsChange(change));
}
示例7: OwnsChangeReturnsFalseIfChangeStartsAfterSpanEnds
public void OwnsChangeReturnsFalseIfChangeStartsAfterSpanEnds() {
// Arrange
Span span = new CodeSpan(new SourceLocation(42, 0, 42), "FooBarBaz");
TextChange change = new TextChange(52, 3, new StringTextBuffer("BooBarBaz"), 3, new StringTextBuffer("Foo"));
// Act/Assert
Assert.IsFalse(span.OwnsChange(change));
}
示例8: OwnsChangeReturnsTrueIfSpanContentEntirelyContainsOldSpan
public void OwnsChangeReturnsTrueIfSpanContentEntirelyContainsOldSpan() {
// Arrange
Span span = new CodeSpan(new SourceLocation(42, 0, 42), "FooBarBaz");
TextChange change = new TextChange(45, 3, new StringTextBuffer("BooBarBaz"), 3, new StringTextBuffer("Foo"));
// Act/Assert
Assert.IsTrue(span.OwnsChange(change));
}
示例9: CheckForStructureChangesRequiresNonNullBufferInChange
public void CheckForStructureChangesRequiresNonNullBufferInChange() {
TextChange change = new TextChange();
ExceptionAssert.ThrowsArgumentException(() => new RazorEditorParser(CreateHost(),
"C:\\Foo.cshtml").CheckForStructureChanges(change),
"change",
String.Format(RazorResources.Structure_Member_CannotBeNull, "Buffer", "TextChange"));
}
示例10: TestIsInsert
public void TestIsInsert() {
// Arrange
ITextBuffer oldBuffer = new Mock<ITextBuffer>().Object;
ITextBuffer newBuffer = new Mock<ITextBuffer>().Object;
TextChange change = new TextChange(0, 0, oldBuffer, 35, newBuffer);
// Assert
Assert.IsTrue(change.IsInsert);
}
示例11: TestIsReplace
public void TestIsReplace() {
// Arrange
ITextBuffer oldBuffer = new Mock<ITextBuffer>().Object;
ITextBuffer newBuffer = new Mock<ITextBuffer>().Object;
TextChange change = new TextChange(0, 5, oldBuffer, 10, newBuffer);
// Assert
Assert.IsTrue(change.IsReplace);
}
示例12: TestIsDelete
public void TestIsDelete()
{
// Arrange
ITextBuffer oldBuffer = new Mock<ITextBuffer>().Object;
ITextBuffer newBuffer = new Mock<ITextBuffer>().Object;
TextChange change = new TextChange(0, 1, oldBuffer, 0, newBuffer);
// Assert
Assert.True(change.IsDelete);
}
示例13: TestDeleteCreatesTheRightSizeChange
public void TestDeleteCreatesTheRightSizeChange()
{
// Arrange
ITextBuffer oldBuffer = new Mock<ITextBuffer>().Object;
ITextBuffer newBuffer = new Mock<ITextBuffer>().Object;
TextChange change = new TextChange(0, 1, oldBuffer, 0, newBuffer);
// Assert
Assert.Equal(0, change.NewText.Length);
Assert.Equal(1, change.OldText.Length);
}
示例14: ApplyChangeReturnsRejectedIfTerminatorStringNull
public void ApplyChangeReturnsRejectedIfTerminatorStringNull() {
// Arrange
var span = new CodeSpan(new SourceLocation(0, 0, 0), "foo");
var change = new TextChange(0, 0, new StringTextBuffer("foo"), 1, new StringTextBuffer("bfoo"));
// Act
PartialParseResult result = span.ApplyChange(change);
// Assert
Assert.AreEqual(PartialParseResult.Rejected, result);
}
示例15: 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;
}