当前位置: 首页>>代码示例>>C#>>正文


C# SourceRange.Contains方法代码示例

本文整理汇总了C#中SourceRange.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# SourceRange.Contains方法的具体用法?C# SourceRange.Contains怎么用?C# SourceRange.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SourceRange的用法示例。


在下文中一共展示了SourceRange.Contains方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestContains

 public void TestContains()
 {
     SourcePosition loc1 = new SourcePosition(0, 1, 1);
     SourcePosition loc2 = new SourcePosition(2, 1, 3);
     SourcePosition loc3 = new SourcePosition(5, 1, 6);
     SourcePosition loc4 = new SourcePosition(6, 1, 7);
     SourcePosition loc5 = new SourcePosition(9, 2, 14);
     SourceRange range1 = new SourceRange(loc1, loc2);
     SourceRange range2 = new SourceRange(loc2, loc4);
     SourceRange range3 = new SourceRange(loc1, loc4);
     SourceRange range4 = new SourceRange(loc1, loc5);
     // Contains(ISourceLocatable)
     Assert.AreEqual(false, SourceRange.Unknown.Contains(SourceRange.Unknown));
     Assert.AreEqual(false, SourceRange.Unknown.Contains(range1));
     Assert.AreEqual(true, range1.Contains(range1));
     Assert.AreEqual(false, range1.Contains(range2));
     Assert.AreEqual(false, range1.Contains(SourceRange.Unknown));
     Assert.AreEqual(false, range2.Contains(range3));
     Assert.AreEqual(false, range2.Contains(range4));
     Assert.AreEqual(true, range3.Contains(range2));
     Assert.AreEqual(true, range4.Contains(range2));
     // Contains(SourcePosition)
     Assert.AreEqual(false, range2.Contains(SourcePosition.Unknown));
     Assert.AreEqual(false, range2.Contains(loc1));
     Assert.AreEqual(true, range2.Contains(loc2));
     Assert.AreEqual(true, range2.Contains(loc3));
     Assert.AreEqual(true, range2.Contains(loc4));
     Assert.AreEqual(false, range2.Contains(loc5));
     // Contains(int)
     Assert.AreEqual(false, range2.Contains(loc1.Index));
     Assert.AreEqual(true, range2.Contains(loc2.Index));
     Assert.AreEqual(true, range2.Contains(loc3.Index));
     Assert.AreEqual(true, range2.Contains(loc4.Index));
     Assert.AreEqual(false, range2.Contains(loc5.Index));
     // Contains(int,int)
     Assert.AreEqual(false, range2.Contains(loc1.Line, loc1.Col));
     Assert.AreEqual(true, range2.Contains(loc2.Line, loc2.Col));
     Assert.AreEqual(true, range2.Contains(loc3.Line, loc3.Col));
     Assert.AreEqual(true, range2.Contains(loc4.Line, loc4.Col));
     Assert.AreEqual(false, range2.Contains(loc5.Line, loc5.Col));
 }
开发者ID:GISwilson,项目名称:Cyjb,代码行数:41,代码来源:UnitTestSourceRange.cs

示例2: AddSelection

        /// <summary>
        /// Adds the selection in the specified TextView (or the active member if there is no selection) to this MultiSelect instance.
        /// </summary>
        public void AddSelection(TextView textView)
        {
            if (textView == null)
                return;
            TextViewSelection textViewSelection = textView.Selection;
            if (textViewSelection == null)
                return;

            PartialSelection newPartialSelection = new PartialSelection(Selections.Count);

            // TODO: Refactor this so we find the selected member in one method (currently we have memberSelected, nodeAtTopOfSelection and selectionScanner performing similar functionality).
            SourcePoint finalCaretPosition = SourcePoint.Empty;
            LanguageElement memberSelected = null;
            if (!textViewSelection.Exists)
            {
                LanguageElement activeMember = CodeRush.Source.ActiveMember;
                if (activeMember != null)
                {
                    SourceRange declareRange = new SourceRange(activeMember.Range.Top, activeMember.NameRange.Bottom);
                    if (declareRange.Contains(textView.Caret.SourcePoint))
                    {
                        SourceRange fullBlockCutRange = activeMember.GetFullBlockCutRange();
                        textView.Selection.Set(fullBlockCutRange);
                        memberSelected = activeMember;
                    }
                    else
                        CodeRush.Command.Execute("SelectionExpand");
                }
                else
                    CodeRush.Command.Execute("SelectionExpand");
                if (!textViewSelection.Exists)
                    return;
            }

            SourceRange selectionRange = new SourceRange(textViewSelection.Range.Top, textViewSelection.Range.Bottom);

            for (int i = Selections.Count - 1; i >= 0; i--)
            {
                PartialSelection compareSelection = Selections[i];
                if (selectionRange.Overlaps(compareSelection.Range))
                {
                    selectionRange = SourceRange.Union(compareSelection.Range, selectionRange);
                    compareSelection.RemoveHighlighter();
                    Selections.RemoveAt(i);
                }
            }
            if (memberSelected != null)
            {
                newPartialSelection.ElementName = memberSelected.Name;
                newPartialSelection.ElementType = memberSelected.ElementType;
                finalCaretPosition = memberSelected.Range.Top;
            }
            else
            {
                LanguageElement nodeAtTopOfSelection = CodeRush.Source.GetNodeAt(selectionRange.Top);
                LanguageElement nodeBeforeEndOfSelection = CodeRush.Source.GetNodeBefore(selectionRange.Bottom);
                if (nodeAtTopOfSelection == nodeBeforeEndOfSelection || nodeAtTopOfSelection.Parents(nodeBeforeEndOfSelection) && selectionRange.Contains(nodeAtTopOfSelection.Range))
                {
                    newPartialSelection.ElementName = nodeAtTopOfSelection.Name;
                    newPartialSelection.ElementType = nodeAtTopOfSelection.ElementType;
                }
                else
                {
                    SelectionScanner selectionScanner = new SelectionScanner();
                    selectionScanner.Scan();
                    if (selectionScanner.ElementsFound == 1)
                        newPartialSelection.ElementName = selectionScanner.ElementName;
                    newPartialSelection.ElementType = selectionScanner.ElementType;
                }
            }
            newPartialSelection.Range = selectionRange;
            SourceRange highlightRange;
            if (memberSelected != null)
            {
                LanguageElement startNode;
                LanguageElement endNode;
                memberSelected.GetFullBlockNodes(out startNode, out endNode);
                highlightRange = new SourceRange(startNode.Range.Top, endNode.Range.Bottom);
                if (Selections.Count == 0)
                    ContainsOnlyMembers = true;
            }
            else
            {
                highlightRange = selectionRange;
                ContainsOnlyMembers = false;
            }
            newPartialSelection.HighlightRange = highlightRange;
            newPartialSelection.Text = textView.TextDocument.GetText(selectionRange);

            if (finalCaretPosition == SourcePoint.Empty)
                finalCaretPosition = textViewSelection.Range.Top;
            newPartialSelection.CaretPosition = finalCaretPosition;
            AddSelection(textView, newPartialSelection);
        }
开发者ID:modulexcite,项目名称:CR_MultiSelect,代码行数:97,代码来源:MultiSelect.cs

示例3: GetAvailability

        private bool GetAvailability(LanguageElement element, TextViewSelection selection, bool lineUp, TextView view)
        {
            HtmlElement activeHtmlElement = GetActiveHtmlElement(element, false);
            if ((activeHtmlElement == null) || !activeHtmlElement.HasAttributes)
            {
                return false;
            }

            SourcePoint start = activeHtmlElement.Range.Start;
            SourcePoint end = activeHtmlElement.Range.End;
            if (activeHtmlElement.HasCloseTag && !(activeHtmlElement is AspDirective))
            {
                end = activeHtmlElement.InnerRange.Start;
            }

            SourceRange signatureRange = new SourceRange(start, end);
            if (!selection.Exists && !signatureRange.Contains(CodeRush.Caret.SourcePoint))
            {
                return false;
            }

            if (((selection != null) && selection.Exists) && !IsValidSelection(activeHtmlElement, selection, signatureRange))
            {
                return false;
            }

            if ((element.HasErrors || HasErrorsInParent(element)) || HasErrorsInChildren(element))
            {
                return false;
            }

            return GetBreakApartAvailability(activeHtmlElement, Options.KeepFirstAttribute, view);
        }
开发者ID:ecabiac,项目名称:coderushcontrib,代码行数:33,代码来源:FormatXamlAttributesPlugin.cs


注:本文中的SourceRange.Contains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。