Change a proxy to make the methods within the host class accessible

 

You can change a proxy to make the methods within the hostType class accessible by:

1)      Remove the abstract keyword from the type declaration (drawback- add-ins will now be able to write code like “Application app = new Application();” instead of being forced to use factory methods).

2)      Replace the “Not Implemented” with code to use.

3)      Create a new instance of the updated hostType and call into it.

However, to call back into the host you need to use the RemoteObject. 

 

In this example, the Application.NewDocument method was changed to display a message box instead of call into the remote object and create the new document on the host side:

    [global::Microsoft.VisualStudio.Tools.Applications.Runtime.HostTypeAttribute("ShapeAppCSharp, Microsoft.VisualStudio.Tools.Applications.Samples.ShapeApp.Application")]

    //public abstract partial class Application : global::System.MarshalByRefObject, global::System.Windows.Forms.IWin32Window

    public partial class Application : global::System.MarshalByRefObject, global::System.Windows.Forms.IWin32Window

    {

        [global::Microsoft.VisualStudio.Tools.Applications.Runtime.HostMemberAttribute("NewDocument", BindingFlags = global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.InvokeMethod)]

        //[global::Microsoft.VisualStudio.Tools.Applications.Runtime.HostMemberAttribute("NewDocument", BindingFlags = global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.InvokeMethod)]

        public virtual void NewDocument() {

            System.Windows.Forms.MessageBox.Show("proxy ShapeApp.Application.NewDocument()");

            throw new global::System.NotImplementedException();

        }

}

 

    [global::System.AddIn.Pipeline.AddInBaseAttribute(ActivatableAs = new global::System.Type[] { typeof(Microsoft.VisualStudio.Tools.Applications.Runtime.IEntryPoint) })]

    public partial class ApplicationEntryPoint : global::Microsoft.VisualStudio.Tools.Applications.Runtime.IExtendedEntryPoint

    {

        public virtual void NewDocument()

        {

            //this.RemoteObject.NewDocument();

 

            Samples.ShapeApp.Application newApp = new Application();

            newApp.NewDocument();

        }

}

 


Posted Jun 05 2009, 02:04 PM by BillL
Copyright Summit Software Company, 2008. All rights reserved.