The sample in this post shows how to
support nested types and implicitly declared events in entry point classes
(note that the nested type is in the entry point class, but is not an entry
point). For types nested in an entry
point class, the workaround in Part I is sufficient, no additional changes to
the proxy are required. For implicitly
declared events in VB, in addition to the workaround discussed in Part II, the
entry point class must also be corrected.
Workaround for nested types (same as Part I):
1) Create
the descriptor file as normal.
2) In
descriptor file, change the isExcluded attribute from true to false all types,
methods and properties in the nested type to expose.
3) Create
the proxy file as normal.
4) In
the proxy file, move the nested type from the namespace “Namespace.OuterType”
into the outer class (or type).
Workaround for implicitly declared events (new step in bold):
1) Create
the descriptor file as normal.
2) In
descriptor file, change the isExcluded attribute from true to false for the
handler created by Visual Basic for the implicitly declared event to
expose.
3) Create
the proxy file as normal.
4) In
the proxy file, move the nested handler type into the class in which the event
was declared.
5) Correct
the delegate name from OuterClass_ImplicitEventHandler to ImplicitEventHandler
6) Correct
the syntax of the event (within the class) from
global::NameSpace.OuterClass_ImplicitEventEventHandler to
globall::NameSpace.OuterClass.ImplicitEventEventHandler
7)
In
the EntryPoint class, correct the syntax of the event from global::NameSpace.OuterClass_ImplicitEventEventHandler
to global::NameSpace.OuterClass.ImplicitEventEventHandler
Types
from the host:
'declaring entry
point class
Partial Public Class
Application
Private
mAppMyNestedObj As AppMyNestedObjectType
Public Property AppMyNestedObj() As
AppMyNestedObjectType
Get
Return
mAppMyNestedObj
End Get
Set(ByVal value As
AppMyNestedObjectType)
mAppMyNestedObj = value
End Set
End Property
'explicit events
require no work around
Public Event ExplicitEvent As
System.EventHandler
'implicit events
create hidden nested types which require a work around
Public Event ImplicitEvent(ByVal
sender As Object,
ByVal e As
System.EventArgs)
'class nested in
an entry point class
Public Class AppMyNestedObjectType
Public Sub New(ByVal nID As String)
mID = nID
End Sub
Private
mID As String
Public Property ID() As String
Get
Return
mID
End
Get
Set(ByVal value As String)
mID = value
End
Set
End Property
Public Sub DoSomething()
'do
something
End Sub
End Class
End Class
ProxyGen
error:
ProxyGen.exe Error: 11110 : Cannot
generate a proxy for the following types, bec
ause they contain an inner type.
ProxyGen does not support nested types. In the
XML descriptor file, nested types are
extracted from the outer type and marked a
s excluded. To generate proxy code for
these types, you must modify the XML desc
riptor file.
NestedTypes_Workaround_VB.Application
NestedTypes_Workaround_VB.Application.ImplicitEventEventHandler
ProxyGen.exe Information: 0 : Finished
ProxyGen.exe Information: 0 : 1 Errors
Descriptor
file (changes in bold):
<!--specify the entry point-->
<Class originalFullyQualifiedName="NestedTypes_Workaround_VB.Application" isExcluded="false" isAddInEntryPoint="false">
<Property
originalName="AppMyNestedObj" isExcluded="false">
<Type>
<TypeReference
type="NestedTypes_Workaround_VB.Application.AppMyNestedObjectType" />
</Type>
<Get
isExcluded="false" />
<Set
isExcluded="false" />
</Property>
<Event
originalName="ExplicitEvent" isExcluded="false">
<Type>
<ExternalTypeReference
isInterface="false" type="System.EventHandler" />
</Type>
</Event>
<Event
originalName="ImplicitEvent" isExcluded="false">
<Type>
<TypeReference
type="NestedTypes_Workaround_VB.Application.ImplicitEventEventHandler" />
</Type>
</Event>
</Class>
<!--Nested Types Fix: change isExcluded
to true-->
<Class originalFullyQualifiedName="NestedTypes_Workaround_VB.Application.AppMyNestedObjectType" isExcluded="false" isAddInEntryPoint="false">
<Method
originalName="DoSomething" isExcluded="false">
<ReturnType>
<ExternalTypeReference
isInterface="false" type="System.Void" />
</ReturnType>
</Method>
<Property
originalName="ID" isExcluded="false">
<Type>
<ExternalTypeReference
isInterface="false" type="System.String" />
</Type>
<Get
isExcluded="false"
/>
<Set
isExcluded="false"
/>
</Property>
</Class>
<!--Nested Types Fix: change isExcluded
to true-->
<Delegate originalFullyQualifiedName="NestedTypes_Workaround_VB.Application.ImplicitEventEventHandler" newName="Application_ImplicitEventEventHandler" isExcluded="false" newNamespace="NestedTypes_Workaround_VB">
<Parameter
originalName="sender">
<Type>
<ExternalTypeReference
isInterface="false" type="System.Object" />
</Type>
</Parameter>
<Parameter
originalName="e">
<Type>
<ExternalTypeReference
isInterface="false" type="System.EventArgs" />
</Type>
</Parameter>
<Type>
<ExternalTypeReference
isInterface="false" type="System.Void" />
</Type>
</Delegate>
Modified
Proxy File (changes in bold):
namespace
NestedTypes_Workaround_VB
{
[global::Microsoft.VisualStudio.Tools.Applications.Runtime.
HostTypeAttribute("NestedTypes_Workaround_VB,
NestedTypes_Workaround_VB.Application")]
public abstract partial class
Application : global::System.MarshalByRefObject
{
public virtual global::NestedTypes_Workaround_VB.Application.AppMyNestedObjectType
AppMyNestedObj
{
[global::Microsoft.VisualStudio.Tools.Applications.Runtime.
HostMemberAttribute("AppMyNestedObj",
BindingFlags = global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.GetProperty)]
get
{ throw new global::System.NotImplementedException();
}
[global::Microsoft.VisualStudio.Tools.Applications.Runtime.
HostMemberAttribute("AppMyNestedObj",
BindingFlags = global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.SetProperty)]
set
{ throw new global::System.NotImplementedException();
}
}
virtual
public event global::System.EventHandler
ExplicitEvent
{
add
{ throw new global::System.NotImplementedException();
}
remove
{ throw new global::System.NotImplementedException();
}
}
//Nested
Types Fix 1D: Corected syntax from _ to
.
//virtual
public event global::NestedTypes_Workaround_VB.Application_ImplicitEventEventHandler
ImplicitEvent
virtual
public event global:: NestedTypes_Workaround_VB.Application.ImplicitEventEventHandler
ImplicitEvent
{
add
{ throw new global::System.NotImplementedException();
}
remove
{ throw new global::System.NotImplementedException();
}
}
//Nested
Types Fix 1B: moved handler for
implicitly typed event into declaring class
[global::Microsoft.VisualStudio.Tools.Applications.Runtime.
HostTypeAttribute("NestedTypes_Workaround_VB,
NestedTypes_Workaround_VB.Application.ImplicitEventEventHandler")]
//Nested
Types Fix 1C: corrected delegate name
removing OuterClass_
//public
delegate void Application_ImplicitEventEventHandler(object sender,
global::System.EventArgs e);
public
delegate void
ImplicitEventEventHandler(object sender, global::System.EventArgs
e);
//Nested
Types Fix 2B: Move the nested type into
the declaring non-entry point class
[global::Microsoft.VisualStudio.Tools.Applications.Runtime.
HostTypeAttribute("NestedTypes_Workaround_VB,
NestedTypes_Workaround_VB.Application.AppMyNestedObjectType")]
public
abstract partial
class AppMyNestedObjectType : global::System.MarshalByRefObject
{
public
virtual string
ID
{
[global::Microsoft.VisualStudio.Tools.Applications.Runtime.HostMemberAttribute("ID", BindingFlags = global::System.Reflection.BindingFlags.Instance
| global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.GetProperty)]
get { throw new global::System.NotImplementedException(); }
[global::Microsoft.VisualStudio.Tools.Applications.Runtime.HostMemberAttribute("ID", BindingFlags = global::System.Reflection.BindingFlags.Instance
| global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.SetProperty)]
set { throw new global::System.NotImplementedException();
}
}
[global::Microsoft.VisualStudio.Tools.Applications.Runtime. HostMemberAttribute("DoSomething", BindingFlags = global::System.Reflection.BindingFlags.Instance
| global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.InvokeMethod)]
public
virtual void
DoSomething() { throw new
global::System.NotImplementedException();
}
}
}
//Nested
Types Fix 1A: move handler for
implicitly typed event into declaring class
//[global::Microsoft.VisualStudio.Tools.Applications.Runtime.
HostTypeAttribute("NestedTypes_Workaround_VB,
NestedTypes_Workaround_VB.Application.ImplicitEventEventHandler")]
//public
delegate void Application_ImplicitEventEventHandler(object sender,
global::System.EventArgs e);
[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
{
//Entry point
class abriviated- only change included
//Nested
Types Fix 1E: cCorected syntax from _ to
.
//public
event global::NestedTypes_Workaround_VB.Application_ImplicitEventEventHandler
ImplicitEvent
public event global::NestedTypes_Workaround_VB.Application.ImplicitEventEventHandler
ImplicitEvent
{
add
{
if
(this.remoteObject != null)
((NestedTypes_Workaround_VB.Application)(this.remoteObject)).ImplicitEvent
+= value;
else
GetDelayedEventsList().Add(
() =>
((NestedTypes_Workaround_VB.Application)(this.remoteObject)).ImplicitEvent
+= value);
}
remove
{
if
(this.remoteObject != null)
((NestedTypes_Workaround_VB.Application)(this.remoteObject)).ImplicitEvent
-= value;
else
GetDelayedEventsList().Add(
() =>
((NestedTypes_Workaround_VB.Application)(this.remoteObject)).ImplicitEvent
-= value);
}
}
private
static global::System.Type remoteType;
}
}
//Nested
Types Fix 2A: Move the nested type into
the declaring non-entry point class
//namespace
NestedTypes_Workaround_VB.Application
//{
//
[global::Microsoft.VisualStudio.Tools.Applications.Runtime.HostTypeAttribute("NestedTypes_Workaround_VB,
NestedTypes_Workaround_VB.Application.AppMyNestedObjectType")]
// public abstract partial class AppMyNestedObjectType
: global::System.MarshalByRefObject
// {
// public virtual string ID
// {
//
[global::Microsoft.VisualStudio.Tools.Applications.Runtime.HostMemberAttribute("ID",
BindingFlags = global::System.Reflection.BindingFlags.Instance |
global::System.Reflection.BindingFlags.Public |
global::System.Reflection.BindingFlags.GetProperty)]
// get { throw new
global::System.NotImplementedException(); }
//
[global::Microsoft.VisualStudio.Tools.Applications.Runtime.HostMemberAttribute("ID",
BindingFlags = global::System.Reflection.BindingFlags.Instance |
global::System.Reflection.BindingFlags.Public |
global::System.Reflection.BindingFlags.SetProperty)]
// set { throw new
global::System.NotImplementedException(); }
// }
//
[global::Microsoft.VisualStudio.Tools.Applications.Runtime.HostMemberAttribute("DoSomething",
BindingFlags = global::System.Reflection.BindingFlags.Instance |
global::System.Reflection.BindingFlags.Public |
global::System.Reflection.BindingFlags.InvokeMethod)]
// public virtual void DoSomething() {
throw new global::System.NotImplementedException(); }
// }
//}
Posted
May 30 2008, 02:01 PM
by
Melody