本文整理汇总了C#中ITextSource.CreateSnapshot方法的典型用法代码示例。如果您正苦于以下问题:C# ITextSource.CreateSnapshot方法的具体用法?C# ITextSource.CreateSnapshot怎么用?C# ITextSource.CreateSnapshot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITextSource
的用法示例。
在下文中一共展示了ITextSource.CreateSnapshot方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Format
public ITextSource Format (PolicyContainer policyParent, string mimeType, ITextSource input, int startOffset, int length)
{
if (startOffset < 0 || startOffset > input.Length)
throw new ArgumentOutOfRangeException (nameof (startOffset), "should be >= 0 && < " + input.Length + " was:" + startOffset);
if (length < 0 || startOffset + length > input.Length)
throw new ArgumentOutOfRangeException (nameof (length), "should be >= 0 && < " + (input.Length - startOffset) + " was:" + length);
try {
return FormatImplementation (policyParent ?? PolicyService.DefaultPolicies, mimeType, input, startOffset, length);
} catch (Exception e) {
LoggingService.LogError ("Error while formatting text.", e);
}
return input.CreateSnapshot (startOffset, length);
}
示例2: Format
public ITextSource Format (PolicyContainer policyParent, ITextSource input, ISegment segment = null)
{
try {
if (segment == null)
return formatter.Format (policyParent, mimeType, input);
return formatter.Format (policyParent, mimeType, input, segment.Offset, segment.EndOffset);
} catch (Exception e) {
LoggingService.LogError ("Error while formatting text.", e);
if (segment == null)
return input;
return input.CreateSnapshot (segment.Offset, segment.Length);
}
}
示例3: ReadOnlyDocument
/// <summary>
/// Creates a new ReadOnlyDocument from the given text source.
/// </summary>
public ReadOnlyDocument(ITextSource textSource)
{
if (textSource == null)
throw new ArgumentNullException("textSource");
// ensure that underlying buffer is immutable
this.textSource = textSource.CreateSnapshot();
List<int> lines = new List<int>();
lines.Add(0);
int offset = 0;
int textLength = textSource.TextLength;
while ((offset = textSource.IndexOfAny(newline, offset, textLength - offset)) >= 0) {
offset++;
if (textSource.GetCharAt(offset - 1) == '\r' && offset < textLength && textSource.GetCharAt(offset) == '\n') {
offset++;
}
lines.Add(offset);
}
this.lines = lines.ToArray();
}
示例4: Parse
public ParseInformation Parse(FileName fileName, ITextSource fileContent, bool fullParseInformationRequested,
IProject parentProject, CancellationToken cancellationToken)
{
AXmlParser parser = new AXmlParser();
AXmlDocument document;
IncrementalParserState newParserState;
if (fileContent.Version is OnDiskTextSourceVersion) {
document = parser.Parse(fileContent, cancellationToken);
newParserState = null;
} else {
document = parser.ParseIncremental(parserState, fileContent, out newParserState, cancellationToken);
}
parserState = newParserState;
XamlUnresolvedFile unresolvedFile = XamlUnresolvedFile.Create(fileName, fileContent, document);
ParseInformation parseInfo;
if (fullParseInformationRequested)
parseInfo = new XamlFullParseInformation(unresolvedFile, document, fileContent.CreateSnapshot());
else
parseInfo = new ParseInformation(unresolvedFile, fileContent.Version, false);
AddTagComments(document, parseInfo, fileContent);
return parseInfo;
}
示例5: DoParseAsync
Task<ProjectEntry> DoParseAsync(ITextSource fileContent, IProject parentProject, bool requestFullParseInformation, CancellationToken cancellationToken)
{
// Create snapshot of file content, if required
bool lookupOpenFileOnTargetThread;
if (fileContent != null) {
lookupOpenFileOnTargetThread = false;
// File content was explicitly specified:
// Let's make a snapshot in case the text source is mutable.
fileContent = fileContent.CreateSnapshot();
} else if (SD.MainThread.InvokeRequired) {
// fileContent == null && not on the main thread:
// Don't fetch the file content right now; if we need to SafeThreadCall() anyways,
// it's better to do so from the background task.
lookupOpenFileOnTargetThread = true;
} else {
// fileContent == null && we are on the main thread:
// Let's look up the file in the list of open files right now
// so that we don't need to SafeThreadCall() later on.
lookupOpenFileOnTargetThread = false;
fileContent = parser.GetFileContent(fileName);
}
Task<ProjectEntry> task;
lock (this) {
if (fileContent != null) {
// Optimization:
// don't start a background task if fileContent was specified and up-to-date parse info is available
int index = FindIndexForProject(parentProject);
int versionComparison = CompareVersions(fileContent.Version);
if (versionComparison == 0 && index >= 0) {
// Ensure we have parse info for the specified project (entry.UnresolvedFile is null for newly registered projects)
// If full parse info is requested, ensure we have full parse info.
if (entries[index].UnresolvedFile != null && !(requestFullParseInformation && entries[index].CachedParseInformation == null)) {
// We already have the requested version parsed, just return it:
return Task.FromResult(entries[index]);
}
}
// Optimization:
// if an equivalent task is already running, return that one instead
if (runningAsyncParseTask != null && (!requestFullParseInformation || runningAsyncParseFullInfoRequested)
&& runningAsyncParseProject == parentProject
&& runningAsyncParseFileContentVersion.BelongsToSameDocumentAs(fileContent.Version)
&& runningAsyncParseFileContentVersion.CompareAge(fileContent.Version) == 0)
{
return runningAsyncParseTask;
}
}
task = new Task<ProjectEntry>(
delegate {
try {
if (lookupOpenFileOnTargetThread) {
fileContent = SD.FileService.GetFileContentForOpenFile(fileName);
}
return DoParse(fileContent, parentProject, requestFullParseInformation, cancellationToken);
} finally {
lock (this) {
runningAsyncParseTask = null;
runningAsyncParseFileContentVersion = null;
runningAsyncParseProject = null;
}
}
}, cancellationToken);
if (fileContent != null && fileContent.Version != null && !cancellationToken.CanBeCanceled) {
runningAsyncParseTask = task;
runningAsyncParseFileContentVersion = fileContent.Version;
runningAsyncParseProject = parentProject;
runningAsyncParseFullInfoRequested = requestFullParseInformation;
}
}
task.Start();
return task;
}
示例6: Replace
/// <summary>
/// Replaces text.
/// </summary>
/// <param name="offset">The starting offset of the text to be replaced.</param>
/// <param name="length">The length of the text to be replaced.</param>
/// <param name="text">The new text.</param>
/// <param name="offsetChangeMap">The offsetChangeMap determines how offsets inside the old text are mapped to the new text.
/// This affects how the anchors and segments inside the replaced region behave.
/// If you pass null (the default when using one of the other overloads), the offsets are changed as
/// in OffsetChangeMappingType.Normal mode.
/// If you pass OffsetChangeMap.Empty, then everything will stay in its old place (OffsetChangeMappingType.CharacterReplace mode).
/// The offsetChangeMap must be a valid 'explanation' for the document change. See <see cref="OffsetChangeMap.IsValidForDocumentChange"/>.
/// Passing an OffsetChangeMap to the Replace method will automatically freeze it to ensure the thread safety of the resulting
/// DocumentChangeEventArgs instance.
/// </param>
public void Replace(int offset, int length, ITextSource text, OffsetChangeMap offsetChangeMap)
{
if (text == null)
throw new ArgumentNullException("text");
text = text.CreateSnapshot();
if (offsetChangeMap != null)
offsetChangeMap.Freeze();
// Ensure that all changes take place inside an update group.
// Will also take care of throwing an exception if inDocumentChanging is set.
BeginUpdate();
try {
// protect document change against corruption by other changes inside the event handlers
inDocumentChanging = true;
try {
// The range verification must wait until after the BeginUpdate() call because the document
// might be modified inside the UpdateStarted event.
ThrowIfRangeInvalid(offset, length);
DoReplace(offset, length, text, offsetChangeMap);
} finally {
inDocumentChanging = false;
}
} finally {
EndUpdate();
}
}
示例7: GetTextFromTextSource
// gets the text from a text source, directly retrieving the underlying rope where possible
static IEnumerable<char> GetTextFromTextSource(ITextSource textSource)
{
if (textSource == null)
throw new ArgumentNullException("textSource");
#if NREFACTORY
if (textSource is ReadOnlyDocument)
textSource = textSource.CreateSnapshot(); // retrieve underlying text source, which might be a RopeTextSource
#endif
RopeTextSource rts = textSource as RopeTextSource;
if (rts != null)
return rts.GetRope();
TextDocument doc = textSource as TextDocument;
if (doc != null)
return doc.rope;
return textSource.Text;
}