HostMemberAttributes and meta classes

 

The HostMemberAttributes are used to reconcile name changes.  When there is no name change the attribute is unnecessary.  VSTA runtime uses this attribute, if available, to determine which type/method to call in the host.  For example, if we change the method name for Application.NewDocument to Application.UpdatedName_NewDocument the method in the proxy will be called Application.UpdatedName_NewDocument and will have the HostMemberAttribute "NewDocument".  If this attribute is removed VSTA will attempt to call Application.UpdatedName_NewDocument in the host and this will fail.  Similarly, if you change a HostMemberAttribute, VSTA will use the attribute name and the call will fail if no methods match the attribute name.  Also, if you switch attribute names, the method for the attribute will be called (this may be useful in generic workarounds).

 

The implementation of the meta classes (classes that aren't classEntryPoint) doesn't matter under normal circumstances- the NotImplementedException or what ever code replaces it should never be reached.  When altering the proxy to use these classes, the code will be reached.

 

 

Descriptor file:

(Application class)

      <Method originalName="NewDocument" newName="UpdatedName_NewDocument" isExcluded="false">

        <ReturnType>

          <ExternalTypeReference isInterface="false" type="System.Void" />

        </ReturnType>

      </Method>

 

Proxy file:

(Application class)

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

        public virtual void UpdatedName_NewDocument() { throw new global::System.NotImplementedException(); }

 

(ApplicationEntryPoint class)

        public virtual void UpdatedName_NewDocument()

        {

            this.RemoteObject.UpdatedName_NewDocument();

        }

 

Add-in:

this.UpdatedName_NewDocument();

 

 


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