c# - add-in for visual studio 2010编译报错Connect类

标签 c# .net visual-studio add-in

这里:

Is there a way to specify outlining defaults in Visual Studio 2008 so that a file opens up with members collapsed by default?

..我可以找到一个编程插件的例子..但不幸的是它没有编译:-(

Error 1

'CollapsedMembers.Connect' does not contain a definition for '_openHandler' and no extension method '_openHandler' accepting a first argument of type 'CollapsedMembers.Connect' could be found (are you missing a using directive or an assembly reference?)

D:\CollapsedMembers\Connect.cs 77 18 CollapsedMembers

事实上,那里没有 _openHandler。我已经尝试了所有 .NET Framework 版本,但遗憾的是没有成功。

在 OnOpenHandler.cs 中,我实现了 OnOpenHandler:

namespace CollapsedMembers
{
    internal class OnOpenHandler
    {
        DTE2 _application = null;
        EnvDTE.Events events = null;
        EnvDTE.DocumentEvents docEvents = null;
... and so on...

有人可以帮忙吗?

[编辑:] Connect.cs 如下所示:

using System;
using Extensibility;
using EnvDTE;
using EnvDTE80;

namespace CollapsedMembers
{
    /// <summary>The object for implementing an Add-in.</summary>
    /// <seealso class='IDTExtensibility2' />
    public class Connect : IDTExtensibility2
    {
        /// <summary>Implements the constructor for the Add-in object. Place your initialization code within this method.</summary>
        public Connect()
        {
        }

        /// <summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary>
        /// <param term='application'>Root object of the host application.</param>
        /// <param term='connectMode'>Describes how the Add-in is being loaded.</param>
        /// <param term='addInInst'>Object representing this Add-in.</param>
        /// <seealso class='IDTExtensibility2' />
        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            _applicationObject = (DTE2)application;
            _addInInstance = (AddIn)addInInst;


            switch (connectMode)
            {
                case ext_ConnectMode.ext_cm_UISetup:
                case ext_ConnectMode.ext_cm_Startup:
                    //Do nothing OnStartup will be called once IDE is initialised.
                    break;
                case ext_ConnectMode.ext_cm_AfterStartup:
                    //The addin was started post startup so we need to call its initialisation manually
                    InitialiseHandlers();
                    break;
            }
        }

        /// <summary>Implements the OnDisconnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being unloaded.</summary>
        /// <param term='disconnectMode'>Describes how the Add-in is being unloaded.</param>
        /// <param term='custom'>Array of parameters that are host application specific.</param>
        /// <seealso class='IDTExtensibility2' />
        public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array custom)
        {
        }

        /// <summary>Implements the OnAddInsUpdate method of the IDTExtensibility2 interface. Receives notification when the collection of Add-ins has changed.</summary>
        /// <param term='custom'>Array of parameters that are host application specific.</param>
        /// <seealso class='IDTExtensibility2' />       
        public void OnAddInsUpdate(ref Array custom)
        {
        }

        /// <summary>Implements the OnStartupComplete method of the IDTExtensibility2 interface. Receives notification that the host application has completed loading.</summary>
        /// <param term='custom'>Array of parameters that are host application specific.</param>
        /// <seealso class='IDTExtensibility2' />
        public void OnStartupComplete(ref Array custom)
        {
            InitialiseHandlers();
        }

        /// <summary>Implements the OnBeginShutdown method of the IDTExtensibility2 interface. Receives notification that the host application is being unloaded.</summary>
        /// <param term='custom'>Array of parameters that are host application specific.</param>
        /// <seealso class='IDTExtensibility2' />
        public void OnBeginShutdown(ref Array custom)
        {
        }

        private DTE2 _applicationObject;
        private AddIn _addInInstance;

        private void InitialiseHandlers()
        {
            this._openHandler = new OnOpenHandler(_applicationObject);
        }
    }
}

最佳答案

_openHandlerConnect 类的成员,它未定义,您正在使用它

private void InitialiseHandlers()
{
    this._openHandler = new OnOpenHandler(_applicationObject);
}

你复制的方法。您需要为 Connect 类定义一个 OnOpenHandler _openHandler 成员。

关于c# - add-in for visual studio 2010编译报错Connect类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13158584/

相关文章:

c# - SmartFormat.NET 列表格式中嵌套占位符错误

css - 使用 ASP MVC4、VS2012 和 Web Essentials 时,如何将 mixins.less 文件与其他 less 文件集成?

c++ - 是否可以在调试期间跳过任意数量的循环? Visual Studio

c# - WCF服务库: BadImageFormatException with 32 bit dll

c# - 如何使用 C# 将分层键值对从字符串转换为 json?

c# - 错误 : Cannot find all types required by the 'async' modifier. 您是否针对错误的框架版本,或缺少对程序集的引用?

visual-studio - 我不明白 VS 2010 中的 bulid 部署包

c# - 如何根据 MigraDoc 中的页面宽度调整表格大小?

c# - 从音频文件而不是麦克风进行语音识别

c# - C++/CLI或C#用于在Windows上创建快速,现代和响应迅速的GUI