本文整理汇总了C#中Microsoft.CodeAnalysis.Text.SourceText.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# SourceText.GetType方法的具体用法?C# SourceText.GetType怎么用?C# SourceText.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.Text.SourceText
的用法示例。
在下文中一共展示了SourceText.GetType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyDocumentTextChanged
protected override async void ApplyDocumentTextChanged (DocumentId id, SourceText text)
{
var document = GetDocument (id);
if (document == null)
return;
bool isOpen;
var filePath = document.FilePath;
Projection projection = null;
foreach (var entry in ProjectionList) {
var p = entry.Projections.FirstOrDefault (proj => proj?.Document?.FileName != null && FilePath.PathComparer.Equals (proj.Document.FileName, filePath));
if (p != null) {
filePath = entry.File.FilePath;
projection = p;
break;
}
}
var data = TextFileProvider.Instance.GetTextEditorData (filePath, out isOpen);
// Guard against already done changes in linked files.
// This shouldn't happen but the roslyn merging seems not to be working correctly in all cases :/
if (document.GetLinkedDocumentIds ().Length > 0 && isOpen && !(text.GetType ().FullName == "Microsoft.CodeAnalysis.Text.ChangedText")) {
return;
}
SourceText formerText;
lock (changedFiles) {
if (changedFiles.TryGetValue (filePath, out formerText)) {
if (formerText.Length == text.Length && formerText.ToString () == text.ToString ())
return;
}
changedFiles [filePath] = text;
}
SourceText oldFile;
if (!isOpen || !document.TryGetText (out oldFile)) {
oldFile = await document.GetTextAsync ();
}
var changes = text.GetTextChanges (oldFile).OrderByDescending (c => c.Span.Start).ToList ();
int delta = 0;
if (!isOpen) {
delta = ApplyChanges (projection, data, changes);
var formatter = CodeFormatterService.GetFormatter (data.MimeType);
if (formatter.SupportsPartialDocumentFormatting) {
var mp = GetMonoProject (CurrentSolution.GetProject (id.ProjectId));
string currentText = data.Text;
foreach (var change in changes) {
delta -= change.Span.Length - change.NewText.Length;
var startOffset = change.Span.Start - delta;
if (projection != null) {
int originalOffset;
if (projection.TryConvertFromProjectionToOriginal (startOffset, out originalOffset))
startOffset = originalOffset;
}
string str;
if (change.NewText.Length == 0) {
str = formatter.FormatText (mp.Policies, currentText, TextSegment.FromBounds (Math.Max (0, startOffset - 1), Math.Min (data.Length, startOffset + 1)));
} else {
str = formatter.FormatText (mp.Policies, currentText, new TextSegment (startOffset, change.NewText.Length));
}
data.ReplaceText (startOffset, change.NewText.Length, str);
}
}
data.Save ();
if (projection != null) {
await UpdateProjectionsDocuments (document, data);
} else {
OnDocumentTextChanged (id, new MonoDevelopSourceText (data), PreservationMode.PreserveValue);
}
FileService.NotifyFileChanged (filePath);
} else {
var formatter = CodeFormatterService.GetFormatter (data.MimeType);
var documentContext = IdeApp.Workbench.Documents.FirstOrDefault (d => FilePath.PathComparer.Compare (d.FileName, filePath) == 0);
var root = await projectChanges.NewProject.GetDocument (id).GetSyntaxRootAsync ();
var annotatedNode = root.DescendantNodesAndSelf ().FirstOrDefault (n => n.HasAnnotation (TypeSystemService.InsertionModeAnnotation));
SyntaxToken? renameTokenOpt = root.GetAnnotatedNodesAndTokens (Microsoft.CodeAnalysis.CodeActions.RenameAnnotation.Kind)
.Where (s => s.IsToken)
.Select (s => s.AsToken ())
.Cast<SyntaxToken?> ()
.FirstOrDefault ();
if (documentContext != null) {
var editor = (TextEditor)data;
await Runtime.RunInMainThread (async () => {
using (var undo = editor.OpenUndoGroup ()) {
var oldVersion = editor.Version;
delta = ApplyChanges (projection, data, changes);
var versionBeforeFormat = editor.Version;
if (formatter.SupportsOnTheFlyFormatting) {
foreach (var change in changes) {
delta -= change.Span.Length - change.NewText.Length;
var startOffset = change.Span.Start - delta;
if (projection != null) {
int originalOffset;
if (projection.TryConvertFromProjectionToOriginal (startOffset, out originalOffset))
//.........这里部分代码省略.........
示例2: ApplyDocumentTextChanged
protected override void ApplyDocumentTextChanged (DocumentId id, SourceText text)
{
var document = GetDocument (id);
if (document == null)
return;
bool isOpen;
var filePath = document.FilePath;
var data = TextFileProvider.Instance.GetTextEditorData (filePath, out isOpen);
// Guard against already done changes in linked files.
// This shouldn't happen but the roslyn merging seems not to be working correctly in all cases :/
if (document.GetLinkedDocumentIds ().Length > 0 && isOpen && !(text.GetType ().FullName == "Microsoft.CodeAnalysis.Text.ChangedText")) {
return;
}
SourceText formerText;
if (changedFiles.TryGetValue (filePath, out formerText)) {
if (formerText.Length == text.Length && formerText.ToString () == text.ToString ())
return;
}
changedFiles [filePath] = text;
Projection projection = null;
foreach (var entry in ProjectionList) {
var p = entry.Projections.FirstOrDefault (proj => FilePath.PathComparer.Equals (proj.Document.FileName, filePath));
if (p != null) {
filePath = entry.File.FilePath;
projection = p;
break;
}
}
SourceText oldFile;
if (!isOpen || !document.TryGetText (out oldFile)) {
oldFile = new MonoDevelopSourceText (data);
}
var changes = text.GetTextChanges (oldFile).OrderByDescending (c => c.Span.Start).ToList ();
int delta = 0;
if (!isOpen) {
delta = ApplyChanges (projection, data, changes);
var formatter = CodeFormatterService.GetFormatter (data.MimeType);
var mp = GetMonoProject (CurrentSolution.GetProject (id.ProjectId));
string currentText = data.Text;
foreach (var change in changes) {
delta -= change.Span.Length - change.NewText.Length;
var startOffset = change.Span.Start - delta;
if (projection != null) {
int originalOffset;
if (projection.TryConvertFromProjectionToOriginal (startOffset, out originalOffset))
startOffset = originalOffset;
}
string str;
if (change.NewText.Length == 0) {
str = formatter.FormatText (mp.Policies, currentText, TextSegment.FromBounds (Math.Max (0, startOffset - 1), Math.Min (data.Length, startOffset + 1)));
} else {
str = formatter.FormatText (mp.Policies, currentText, new TextSegment (startOffset, change.NewText.Length));
}
data.ReplaceText (startOffset, change.NewText.Length, str);
}
data.Save ();
OnDocumentTextChanged (id, new MonoDevelopSourceText (data), PreservationMode.PreserveValue);
FileService.NotifyFileChanged (filePath);
} else {
var formatter = CodeFormatterService.GetFormatter (data.MimeType);
var documentContext = IdeApp.Workbench.Documents.FirstOrDefault (d => FilePath.PathComparer.Compare (d.FileName, filePath) == 0);
if (documentContext != null) {
var editor = (TextEditor)data;
using (var undo = editor.OpenUndoGroup ()) {
delta = ApplyChanges (projection, data, changes);
foreach (var change in changes) {
delta -= change.Span.Length - change.NewText.Length;
var startOffset = change.Span.Start - delta;
if (projection != null) {
int originalOffset;
if (projection.TryConvertFromProjectionToOriginal (startOffset, out originalOffset))
startOffset = originalOffset;
}
if (change.NewText.Length == 0) {
formatter.OnTheFlyFormat (editor, documentContext, TextSegment.FromBounds (Math.Max (0, startOffset - 1), Math.Min (data.Length, startOffset + 1)));
} else {
formatter.OnTheFlyFormat (editor, documentContext, new TextSegment (startOffset, change.NewText.Length));
}
}
}
}
OnDocumentTextChanged (id, new MonoDevelopSourceText(data.CreateDocumentSnapshot ()), PreservationMode.PreserveValue);
Runtime.RunInMainThread (() => {
if (IdeApp.Workbench != null)
foreach (var w in IdeApp.Workbench.Documents)
w.StartReparseThread ();
});
}
}