我可以在Visual Studio扩展中操作ASPX页面吗

时间:2019-12-17 22:15:36

标签: c# visual-studio vs-extensibility

我有一个扩展程序,使我可以在Visual Studio扩展程序中操作Windows窗体(设置属性,检查值等)。

我使用以下代码来获取Winforms Designer,以便我可以遍历它来获取所有控件。

    public static IDesignerHost GetCurrentDesignerHost(IServiceProvider p_serviceProvider, bool p_saveHost)
    {
        IDesignerHost designerHost = null;
        object objDocFrame = null;
        IntPtr ppHier;
        IVsMultiItemSelect ppMIS;
        IntPtr ppSC;
        uint pitemid;
        IVsMonitorSelection vsMonSel;

        vsMonSel = p_serviceProvider.GetService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection;
        vsMonSel.GetCurrentElementValue((uint)VSConstants.VSSELELEMID.SEID_DocumentFrame, out objDocFrame);
        vsMonSel.GetCurrentSelection(out ppHier, out pitemid, out ppMIS, out ppSC);

        if (objDocFrame != null)
        {
            IVsWindowFrame docFrame = (IVsWindowFrame)objDocFrame;
            object objDocView = null;

            // retrieves the IUnknown of the DocView object
            docFrame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out objDocView);

            // QI for IServiceProvider
            System.IServiceProvider sp = objDocView as System.IServiceProvider;

            if (sp != null)
            {
                // QueryService to get the IDesignerHost
                designerHost = sp.GetService(typeof(IDesignerHost)) as IDesignerHost;
            }
        }

        if (p_saveHost)
        {
            m_lastHost = designerHost;
        }

        return designerHost;
    }

是否有类似的机制可以对ASPX页面执行相同的操作。我希望能够添加/删除/更新属性。通过代码添加/更新/删除控件和子控件。

0 个答案:

没有答案
相关问题