本文整理汇总了C#中SnapshotSpan.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# SnapshotSpan.Contains方法的具体用法?C# SnapshotSpan.Contains怎么用?C# SnapshotSpan.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SnapshotSpan
的用法示例。
在下文中一共展示了SnapshotSpan.Contains方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AugmentQuickInfoSession
/// <inheritdoc />
public void AugmentQuickInfoSession(IQuickInfoSession session, IList<object> quickInfoContent,
out ITrackingSpan applicableToSpan)
{
applicableToSpan = null;
var tagAggregator = provider.AggregatorFactory.CreateTagAggregator<IClassificationTag>(session.TextView);
var triggerPoint = session.GetTriggerPoint(textBuffer.CurrentSnapshot);
if(triggerPoint != null)
{
SnapshotSpan tagSpan;
var lineSpan = triggerPoint.Value.GetContainingLine();
string elementName = null, attrName = null, identifier = null, name;
UIElement content;
// Get the tags for the line containing the mouse point
foreach(IMappingTagSpan<IClassificationTag> curTag in tagAggregator.GetTags(
new SnapshotSpan(lineSpan.Start, lineSpan.End)))
{
name = curTag.Tag.ClassificationType.Classification.ToLowerInvariant();
tagSpan = curTag.Span.GetSpans(textBuffer).First();
if(name.IndexOf("identifier", StringComparison.Ordinal) != -1)
name = "identifier";
switch(name)
{
case "xml doc tag":
// Track the last seen element or attribute. The classifier in VS2013 and earlier does
// not break up the XML comments into elements and attributes so we may get a mix of text
// in the "tag".
attrName = tagSpan.GetText();
// If it contains "cref", ten next XML doc attribute value will be the target
if(attrName.IndexOf("cref=", StringComparison.Ordinal) != -1 && enableInCRef)
attrName = "cref";
// As above, for conceptualLink, the next XML doc attribute will be the target
if(attrName.StartsWith("<conceptualLink", StringComparison.Ordinal))
attrName = "conceptualLink";
// For token, the next XML doc comment will contain the token name
if(attrName == "<token>")
attrName = "token";
break;
case "xml doc attribute":
if((attrName == "cref" || attrName == "conceptualLink") &&
tagSpan.Contains(triggerPoint.Value) && tagSpan.Length > 2)
{
// Drop the quotes from the span
var span = new SnapshotSpan(tagSpan.Snapshot, tagSpan.Start + 1,
tagSpan.Length - 2);
content = this.CreateInfoText(attrName, span.GetText());
if(content != null)
{
applicableToSpan = textBuffer.CurrentSnapshot.CreateTrackingSpan(span,
SpanTrackingMode.EdgeExclusive);
quickInfoContent.Add(content);
}
return;
}
break;
case "xml doc comment":
if(attrName == "token" && tagSpan.Contains(triggerPoint.Value) && tagSpan.Length > 1)
{
content = this.CreateInfoText(attrName, tagSpan.GetText());
if(content != null)
{
applicableToSpan = textBuffer.CurrentSnapshot.CreateTrackingSpan(tagSpan,
SpanTrackingMode.EdgeExclusive);
quickInfoContent.Add(content);
}
return;
}
break;
// VS2015 is more specific in its classifications
case "xml doc comment - name":
elementName = tagSpan.GetText().Trim();
break;
case "xml doc comment - attribute name":
attrName = tagSpan.GetText().Trim();
identifier = null;
if(attrName == "cref" && !enableInCRef)
attrName = null;
break;
case "xml doc comment - attribute value":
//.........这里部分代码省略.........
示例2: ProcessSpans
//=====================================================================
/// <inheritdoc />
protected override bool ProcessSpans(SnapshotSpan mousePoint, IList<ClassificationSpan> spans)
{
string elementName = null, attrName = null, identifier = null;
foreach(var classification in spans)
{
string name = classification.ClassificationType.Classification.ToLowerInvariant();
// Not supporting VB for now due to problems looking up identifiers
//if(name.StartsWith("vb ", StringComparison.Ordinal))
// name = name.Substring(3);
if(name.IndexOf("identifier", StringComparison.Ordinal) != -1)
name = "identifier";
// Highlight the span if it matches what we are looking for and it contains the mouse span
switch(name)
{
case "xml doc tag":
// Track the last seen element or attribute. The classifier in VS2013 and earlier does
// not break up the XML comments into elements and attributes so we may get a mix of text
// in the "tag".
attrName = classification.Span.GetText();
// If it contains "cref", the next XML doc attribute value will be the target
if(attrName.IndexOf("cref=", StringComparison.Ordinal) != -1 && enableInCRef)
attrName = "cref";
// As above, for conceptualLink, the next XML doc attribute will be the target
if(attrName.StartsWith("<conceptualLink", StringComparison.Ordinal))
attrName = "conceptualLink";
// For token, the next XML doc comment will contain the token name
if(attrName == "<token>")
attrName = "token";
break;
case "xml doc attribute":
if((attrName == "cref" || attrName == "conceptualLink") &&
classification.Span.Contains(mousePoint) && classification.Span.Length > 2)
{
// Drop the quotes from the span
var span = new SnapshotSpan(classification.Span.Snapshot, classification.Span.Start + 1,
classification.Span.Length - 2);
if(this.SetHighlightSpan(span, (attrName == "cref") ? "codeEntityReference" : "link"))
return true;
}
break;
case "xml doc comment":
if(attrName == "token" && classification.Span.Contains(mousePoint) &&
classification.Span.Length > 1)
{
if(this.SetHighlightSpan(classification.Span, "token"))
return true;
}
break;
// VS2015 is more specific in its classifications
case "xml doc comment - name":
elementName = classification.Span.GetText().Trim();
break;
case "xml doc comment - attribute name":
attrName = classification.Span.GetText().Trim();
identifier = null;
if(attrName == "cref" && !enableInCRef)
attrName = null;
break;
case "xml doc comment - attribute value":
if((attrName == "cref" || (elementName == "conceptualLink" && attrName == "target")) &&
classification.Span.Contains(mousePoint) && classification.Span.Length > 1)
{
if(this.SetHighlightSpan(classification.Span,
(attrName == "cref") ? "codeEntityReference" : "link"))
return true;
}
break;
case "identifier":
case "keyword":
case "operator":
if(attrName != null)
{
identifier += classification.Span.GetText();
if(name == "keyword")
identifier += " ";
}
break;
case "punctuation":
if(identifier != null)
identifier += classification.Span.GetText();
//.........这里部分代码省略.........
示例3: ProcessSpans
/// <summary>
/// This is used to process the spans and try to figure out whether or not we have something we can use
/// for Go To Definition and, i so, the definition type.
/// </summary>
/// <param name="cursorPos">The cursor position.</param>
/// <param name="spans">The spans to process.</param>
/// <param name="definitionType">On return, this contains the definition type if one was found or null
/// if not.</param>
/// <returns>The snapshot span for the definition if one was found, null if not</returns>
private SnapshotSpan? ProcessSpans(SnapshotPoint cursorPos, IList<ClassificationSpan> spans,
out string definitionType)
{
string elementName = null, attrName = null, identifier = null, spanText;
definitionType = null;
foreach(var classification in spans)
{
string name = classification.ClassificationType.Classification.ToLowerInvariant();
// Not supporting VB for now due to problems looking up identifiers
//if(name.StartsWith("vb ", StringComparison.Ordinal))
// name = name.Substring(3);
if(name.IndexOf("identifier", StringComparison.Ordinal) != -1)
name = "identifier";
// Return the span if it matches what we are looking for and it contains the cursor
switch(name)
{
case "xml name":
elementName = classification.Span.GetText();
break;
case "xml attribute":
attrName = classification.Span.GetText();
break;
case "xml attribute value":
if(classification.Span.Contains(cursorPos))
{
if((elementName == "image" || elementName == "link") && attrName == "xlink:href")
{
definitionType = elementName;
return classification.Span;
}
return null;
}
break;
case "xml text":
if(classification.Span.Contains(cursorPos))
{
spanText = classification.Span.GetText().Trim();
switch(elementName)
{
case "codeEntityReference":
if(spanText.IsCodeEntityReference())
{
definitionType = elementName;
return classification.Span;
}
break;
case "codeReference":
if(spanText.IsCodeReferenceId())
{
definitionType = elementName;
return classification.Span;
}
break;
case "token":
definitionType = elementName;
return classification.Span;
default:
// We only get info about the current line so we may just get some XML text
// if the starting tag is on a prior line. In such cases, see if the text
// looks like an entity reference or a code reference ID. If so, return it
// as the definition. If not, ignore it.
if(String.IsNullOrWhiteSpace(elementName))
{
// Ignore any leading whitespace on the span
string highlightText = classification.Span.GetText();
int offset = highlightText.Length - highlightText.TrimStart().Length;
var textSpan = new SnapshotSpan(classification.Span.Snapshot,
classification.Span.Start.Position + offset,
classification.Span.Length - offset);
if(spanText.IsCodeEntityReference())
{
definitionType = "codeEntityReference";
return textSpan;
}
else
if(spanText.IsCodeReferenceId())
//.........这里部分代码省略.........