EditArray 类

将多个编辑操作创建单个操作。

此 API 不兼容 CLS。 

继承层次结构

System.Object
  Microsoft.VisualStudio.Package.EditArray

命名空间:  Microsoft.VisualStudio.Package
程序集:   Microsoft.VisualStudio.Package.LanguageService.9.0(在 Microsoft.VisualStudio.Package.LanguageService.9.0.dll 中)
  Microsoft.VisualStudio.Package.LanguageService.11.0(在 Microsoft.VisualStudio.Package.LanguageService.11.0.dll 中)
  Microsoft.VisualStudio.Package.LanguageService(在 Microsoft.VisualStudio.Package.LanguageService.dll 中)
  Microsoft.VisualStudio.Package.LanguageService.10.0(在 Microsoft.VisualStudio.Package.LanguageService.10.0.dll 中)

语法

声明
<CLSCompliantAttribute(False)> _
Public Class EditArray _
    Implements IEnumerable, IDisposable
[CLSCompliantAttribute(false)]
public class EditArray : IEnumerable, IDisposable

EditArray 类型公开以下成员。

构造函数

  名称 说明
公共方法 EditArray 使用 Source 对象和 IVsTextView 对象, EditArray 初始化类的新实例。

页首

属性

  名称 说明
公共属性 Count 获取数字编辑在 EditArray 对象表示的操作。
公共属性 Source 获取与此 EditArray 对象关联的 Source 对象。
公共属性 TextView 获取与此 EditArray 对象关联的 IVsTextView 对象。

页首

方法

  名称 说明
公共方法 Add 添加到数组中指定的 EditSpan 对象编辑操作。
公共方法 ApplyEdits 将所有编辑器中累积的操作。
公共方法 Dispose 配置 EditArray 对象及其资源。
公共方法 Equals 确定指定的对象是否等于当前对象。 (继承自 Object。)
受保护的方法 Finalize 关闭 EditArray 对象。 (重写 Object.Finalize()。)
公共方法 GetEnumerator 获取编辑操作的一个默认的枚举器。
公共方法 GetHashCode 用作特定类型的哈希函数。 (继承自 Object。)
公共方法 GetType 获取当前实例的 Type。 (继承自 Object。)
受保护的方法 MemberwiseClone 创建当前 Object 的浅表副本。 (继承自 Object。)
公共方法 ToString 将数组编辑操作。已格式化的字符串。 (重写 Object.ToString()。)

页首

备注

此类包装多个编辑操作创建可以取消,当更新源文件中的单个操作。这种效率通过将获取相邻编辑操作。此外,此类确保现有标记例如断点和书签不会丢失,当 " 编辑操作适用于源文件时。

此类通常用于包装格式设置操作,源多行在可更改似乎单个操作给用户。

,如果 IVsTextView 对象可用,若要创建单个编辑操作,该类使用 CompoundViewAction 类;否则,使用 CompoundAction 类。

在 EditArray 对象,编辑操作是 INSERT 或替换。删除已替换字符串为 null 的替换的一种特例。

对实现者的说明

此类包含所需的所有功能组合,并且应用多个版本。不需要从该类派生。

对调用者的说明

若要包装多个编辑操作,实例化新的 EditArray 对象并调用 Add 方法与该范围的一个或多个受影响。最后,调用 ApplyEdits 方法将任何直接编辑。

示例

这是的示例演示如何替换或插入可能包含文档属性信息) 的第一行文档,例如, (。虽然这说明一个编辑操作,该示例可以轻松地扩展支持多个行,并多个编辑操作。

using Microsoft.VisualStudio.Package;

namespace MyLanguagePackage
{
    class MyLanguageService : LanguageService
    {
        void SetPropertyValue(string propertyName, string propertyValue)
        {
            int lineNumberToReplace = 0;
            string propertyLine = String.Format("//!{0} = {1}",
                                                propertyName,
                                                propertyValue);
            string documentLine = src.GetLine(lineNumberToReplace);
            bool fInsertLine = true;
            if (documentLine.IndexOf("//!") == 0))
            {
                fInsertLine = false;
            }

            // Now insert or replace the line
            EditArray editArray = new EditArray(this.LastActiveTextView,
                                                true,
                                                "Update property");
            if (editArray != null)
            {
                TextSpan span = new TextSpan();
                if (fInsertLine)
                {
                    span.iStartLine  = lineNumberToReplace;
                    span.iStartIndex = 0;
                    span.IEndLine    = lineNumberToReplace;
                    span.iEndIndex   = 0;
                    propertyLine += "\n";
                }
                else
                {
                    int lineLength = 0;
                    src.GetLines().GetLengthOfLine(lineNumberToReplace,out lineLength);
                    span.iStartLine  = lineNumberToReplace;
                    span.iStartIndex = 0;
                    span.iEndLine    = lineNumberToReplace;
                    span.iEndIndex   = lineLength;
                }

                editArray.Add(new EditSpan(span, propertyLine));
                // Multiple Adds can be done here before ApplyEdits
                editArray.ApplyEdits();
            }
        }
    }
}

线程安全

此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。

请参见

参考

Microsoft.VisualStudio.Package 命名空间