473,770 Members | 2,096 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to auto generate interface implementations

I've created an "Add Item" wizard for VB.NET 2003 that allows a user to add a
specialized class that works with my application framework. In the wizard,
the user can select the interfaces they would like to support. During the
code generation phase, I add an "Implements Ixxx" for each interface they
select, but I've not yet figured out how to add the skeleton implementation
for those interfaces. Once the user opens the class in the VS IDE, they
can position the cursor after the interface name and hit return to
auto-generate the implementation. Is there a way to programmaticall y cause
VB.NET to generate the skeleton implementation for these interfaces using the
extensibility model?

Thanks!
Bill
Nov 21 '05 #1
8 5822
Hi

Based on my knowledge, this job done by VS.NET IDE is achieved by
Intellisense which is not exposed by DTE(IDE) Object Modal.
So far I think we have to do that ourselves.
Here is a similar issue about get...set generator.
http://www.codeproject.com/macro/PropertyGenerator.asp

If you have question about the DTE object modal, you may try to post in the
specifed VS.NET IDE extensive newsgroup.
microsoft.publi c.vstudio.exten sibility

If you still have any concern please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #2
Bill,
In addition to Peter's comments.

What are you using to generate the class itself?

Have you considered using Reflection to read the definition of the
Interface, then adding those members to the code that you are creating?

I will try to post an example of using Reflection to read the definition of
an Interface to generate code later...

Hope this helps
Jay

"Bill Rust" <n5****@communi ty.nospam> wrote in message
news:34******** *************** ***********@mic rosoft.com...
| I've created an "Add Item" wizard for VB.NET 2003 that allows a user to
add a
| specialized class that works with my application framework. In the
wizard,
| the user can select the interfaces they would like to support. During the
| code generation phase, I add an "Implements Ixxx" for each interface they
| select, but I've not yet figured out how to add the skeleton
implementation
| for those interfaces. Once the user opens the class in the VS IDE, they
| can position the cursor after the interface name and hit return to
| auto-generate the implementation. Is there a way to programmaticall y
cause
| VB.NET to generate the skeleton implementation for these interfaces using
the
| extensibility model?
|
| Thanks!
| Bill
|
|
Nov 21 '05 #3
Hi Peter,

Thanks for your suggestions. I'll take a look at the PropertyGenerat or
example you cited.

Best regards,
Bill

""Peter Huang" [MSFT]" wrote:
Hi

Based on my knowledge, this job done by VS.NET IDE is achieved by
Intellisense which is not exposed by DTE(IDE) Object Modal.
So far I think we have to do that ourselves.
Here is a similar issue about get...set generator.
http://www.codeproject.com/macro/PropertyGenerator.asp

If you have question about the DTE object modal, you may try to post in the
specifed VS.NET IDE extensive newsgroup.
microsoft.publi c.vstudio.exten sibility

If you still have any concern please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #4
Hi Jay,

Thank you for your reply. I figured reflection could be used to
accomplished this task, but I was trying to avoid coding it if the capability
was already available in the DTE. Since it is not, I would sure appreciate
any sample code you can provide.

Best regards,
Bill

"Jay B. Harlow [MVP - Outlook]" wrote:
Bill,
In addition to Peter's comments.

What are you using to generate the class itself?

Have you considered using Reflection to read the definition of the
Interface, then adding those members to the code that you are creating?

I will try to post an example of using Reflection to read the definition of
an Interface to generate code later...

Hope this helps
Jay

"Bill Rust" <n5****@communi ty.nospam> wrote in message
news:34******** *************** ***********@mic rosoft.com...
| I've created an "Add Item" wizard for VB.NET 2003 that allows a user to
add a
| specialized class that works with my application framework. In the
wizard,
| the user can select the interfaces they would like to support. During the
| code generation phase, I add an "Implements Ixxx" for each interface they
| select, but I've not yet figured out how to add the skeleton
implementation
| for those interfaces. Once the user opens the class in the VS IDE, they
| can position the cursor after the interface name and hit return to
| auto-generate the implementation. Is there a way to programmaticall y
cause
| VB.NET to generate the skeleton implementation for these interfaces using
the
| extensibility model?
|
| Thanks!
| Bill
|
|

Nov 21 '05 #5
Bill,
Here is an example that uses Reflection & the Code Dom to implement an
interface.

There seems to be a problem with the CodeMemberEvent .Implementation Types
member of the CodeDom. For example if I

Implements System.Componen tModel.ICompone nt
My routine creates:

Public Event Disposed As System.EventHan dler

Instead of:

Public Event Disposed As System.EventHan dler Implements
IComponent.Disp osed

The code for Properties & Methods work, however Events fail, so I'm not sure
what the problem is. I'm checking into it. Cannot think of a workaround
right now.

You can use CodeTypeMember. Attributes to control the visibility of the
generated members. Or use PrivateImplemen tationType member of
CodeMemberEvent , CodeMemberPrope rty & CodeMemberMetho d to "hide" the
implementation of the methods...

Hope this helps
Jay

---x--- cut here ---x---
Option Strict On
Option Explicit On

Imports System.CodeDom
Imports System.CodeDom. Compiler

Imports System.IO
Imports System.Reflecti on

Public Module GenerateInterfa ce

Public Sub Main()
Dim unit As New CodeCompileUnit

Dim ns As New CodeNamespace(" Sample")
unit.Namespaces .Add(ns)

Dim type As CodeTypeDeclara tion = BuildClass(ns, "BillRust",
GetType(Object) )

ImplementInterf ace(type,
GetType(System. ComponentModel. IBindingList))

GenerateCode(un it, "BillRust.v b", New VBCodeProvider)
End Sub

Private Sub ImplementInterf ace(ByVal baseType As CodeTypeDeclara tion,
ByVal implementedType As Type)
baseType.BaseTy pes.Add(New CodeTypeReferen ce(implementedT ype))

ImplementInterf aceMembers(base Type, implementedType )

For Each baseInterface As Type In implementedType .GetInterfaces( )
ImplementInterf aceMembers(base Type, baseInterface)
Next

End Sub

Private Sub ImplementInterf aceMembers(ByVa l baseType As
CodeTypeDeclara tion, ByVal implementedType As Type)
ImplementInterf aceEvents(baseT ype, implementedType )
ImplementInterf aceProperties(b aseType, implementedType )
ImplementInterf aceMethods(base Type, implementedType )
End Sub

Private Sub ImplementInterf aceEvents(ByVal baseType As
CodeTypeDeclara tion, ByVal implementedType As Type)
For Each [event] As EventInfo In implementedType .GetEvents()
Dim member As New CodeMemberEvent
member.Name = [event].Name
member.Attribut es = MemberAttribute s.Public
member.Type = New CodeTypeReferen ce([event].EventHandlerTy pe)
member.Implemen tationTypes.Add (implementedTyp e)
baseType.Member s.Add(member)
Next
End Sub

Private Sub ImplementInterf aceProperties(B yVal baseType As
CodeTypeDeclara tion, ByVal implementedType As Type)
For Each [property] As PropertyInfo In
implementedType .GetProperties( )
Dim member As New CodeMemberPrope rty
member.Name = [property].Name
member.Attribut es = MemberAttribute s.Public
member.HasGet = [property].CanRead
member.HasSet = [property].CanWrite
member.Type = New CodeTypeReferen ce([property].PropertyType)
ImplementParame ters(member.Par ameters,
[property].GetIndexParame ters())
member.Implemen tationTypes.Add (implementedTyp e)
baseType.Member s.Add(member)
Next
End Sub

Private Sub ImplementInterf aceMethods(ByVa l baseType As
CodeTypeDeclara tion, ByVal implementedType As Type)
Static void As Type = Type.GetType("S ystem.Void")
For Each [method] As MethodInfo In implementedType .GetMethods()
If Not [method].IsSpecialName Then
Dim member As New CodeMemberMetho d
member.Attribut es = MemberAttribute s.Public
member.Name = [method].Name
member.ReturnTy pe = New
CodeTypeReferen ce([method].ReturnType)
ImplementParame ters(member.Par ameters,
[method].GetParameters( ))
member.Implemen tationTypes.Add (implementedTyp e)
baseType.Member s.Add(member)
End If
Next
End Sub

Private Sub ImplementParame ters(ByVal outputParameter s As
CodeParameterDe clarationExpres sionCollection, ByVal inputParameters () As
ParameterInfo)
For Each parameter As ParameterInfo In inputParameters
Dim value As New CodeParameterDe clarationExpres sion
value.Name = parameter.Name
value.Type = New CodeTypeReferen ce(parameter.Pa rameterType)
outputParameter s.Add(value)
Next
End Sub

Private Function BuildClass(ByVa l ns As CodeNamespace, ByVal name As
String, ByVal baseType As Type) As CodeTypeDeclara tion
Dim type As New CodeTypeDeclara tion(name)
ns.Types.Add(ty pe)

type.BaseTypes. Add(baseType)

Return type
End Function

Private Sub GenerateCode(By Val unit As CodeCompileUnit , ByVal file As
String, ByVal provider As CodeDomProvider )
Dim output As New StreamWriter(fi le)
Dim generator As ICodeGenerator = provider.Create Generator()
Dim options As New CodeGeneratorOp tions
options.BlankLi nesBetweenMembe rs = True
options.Bracing Style = "C"

unit.UserData.A dd("AllowLateBo und", False)
unit.UserData.A dd("RequireVari ableDeclaration ", True)

Try
generator.Gener ateCodeFromComp ileUnit(unit, output, options)
Catch e As Exception
Debug.WriteLine (e, "GenerateCo de")
Finally
output.Flush()
output.Close()
provider.Dispos e()
End Try
End Sub

End Module

---x--- cut here ---x---

"Bill Rust" <n5****@communi ty.nospam> wrote in message
news:50******** *************** ***********@mic rosoft.com...
| Hi Jay,
|
| Thank you for your reply. I figured reflection could be used to
| accomplished this task, but I was trying to avoid coding it if the
capability
| was already available in the DTE. Since it is not, I would sure
appreciate
| any sample code you can provide.
|
| Best regards,
| Bill
|
| "Jay B. Harlow [MVP - Outlook]" wrote:
|
| > Bill,
| > In addition to Peter's comments.
| >
| > What are you using to generate the class itself?
| >
| > Have you considered using Reflection to read the definition of the
| > Interface, then adding those members to the code that you are creating?
| >
| > I will try to post an example of using Reflection to read the definition
of
| > an Interface to generate code later...
| >
| > Hope this helps
| > Jay
| >
| > "Bill Rust" <n5****@communi ty.nospam> wrote in message
| > news:34******** *************** ***********@mic rosoft.com...
| > | I've created an "Add Item" wizard for VB.NET 2003 that allows a user
to
| > add a
| > | specialized class that works with my application framework. In the
| > wizard,
| > | the user can select the interfaces they would like to support. During
the
| > | code generation phase, I add an "Implements Ixxx" for each interface
they
| > | select, but I've not yet figured out how to add the skeleton
| > implementation
| > | for those interfaces. Once the user opens the class in the VS IDE,
they
| > | can position the cursor after the interface name and hit return to
| > | auto-generate the implementation. Is there a way to programmaticall y
| > cause
| > | VB.NET to generate the skeleton implementation for these interfaces
using
| > the
| > | extensibility model?
| > |
| > | Thanks!
| > | Bill
| > |
| > |
| >
| >
| >
Nov 21 '05 #6
Thanks, Jay. I'll give it a try :-)

"Jay B. Harlow [MVP - Outlook]" wrote:
Bill,
Here is an example that uses Reflection & the Code Dom to implement an
interface.

There seems to be a problem with the CodeMemberEvent .Implementation Types
member of the CodeDom. For example if I

Implements System.Componen tModel.ICompone nt
My routine creates:

Public Event Disposed As System.EventHan dler

Instead of:

Public Event Disposed As System.EventHan dler Implements
IComponent.Disp osed

The code for Properties & Methods work, however Events fail, so I'm not sure
what the problem is. I'm checking into it. Cannot think of a workaround
right now.

You can use CodeTypeMember. Attributes to control the visibility of the
generated members. Or use PrivateImplemen tationType member of
CodeMemberEvent , CodeMemberPrope rty & CodeMemberMetho d to "hide" the
implementation of the methods...

Hope this helps
Jay

---x--- cut here ---x---
Option Strict On
Option Explicit On

Imports System.CodeDom
Imports System.CodeDom. Compiler

Imports System.IO
Imports System.Reflecti on

Public Module GenerateInterfa ce

Public Sub Main()
Dim unit As New CodeCompileUnit

Dim ns As New CodeNamespace(" Sample")
unit.Namespaces .Add(ns)

Dim type As CodeTypeDeclara tion = BuildClass(ns, "BillRust",
GetType(Object) )

ImplementInterf ace(type,
GetType(System. ComponentModel. IBindingList))

GenerateCode(un it, "BillRust.v b", New VBCodeProvider)
End Sub

Private Sub ImplementInterf ace(ByVal baseType As CodeTypeDeclara tion,
ByVal implementedType As Type)
baseType.BaseTy pes.Add(New CodeTypeReferen ce(implementedT ype))

ImplementInterf aceMembers(base Type, implementedType )

For Each baseInterface As Type In implementedType .GetInterfaces( )
ImplementInterf aceMembers(base Type, baseInterface)
Next

End Sub

Private Sub ImplementInterf aceMembers(ByVa l baseType As
CodeTypeDeclara tion, ByVal implementedType As Type)
ImplementInterf aceEvents(baseT ype, implementedType )
ImplementInterf aceProperties(b aseType, implementedType )
ImplementInterf aceMethods(base Type, implementedType )
End Sub

Private Sub ImplementInterf aceEvents(ByVal baseType As
CodeTypeDeclara tion, ByVal implementedType As Type)
For Each [event] As EventInfo In implementedType .GetEvents()
Dim member As New CodeMemberEvent
member.Name = [event].Name
member.Attribut es = MemberAttribute s.Public
member.Type = New CodeTypeReferen ce([event].EventHandlerTy pe)
member.Implemen tationTypes.Add (implementedTyp e)
baseType.Member s.Add(member)
Next
End Sub

Private Sub ImplementInterf aceProperties(B yVal baseType As
CodeTypeDeclara tion, ByVal implementedType As Type)
For Each [property] As PropertyInfo In
implementedType .GetProperties( )
Dim member As New CodeMemberPrope rty
member.Name = [property].Name
member.Attribut es = MemberAttribute s.Public
member.HasGet = [property].CanRead
member.HasSet = [property].CanWrite
member.Type = New CodeTypeReferen ce([property].PropertyType)
ImplementParame ters(member.Par ameters,
[property].GetIndexParame ters())
member.Implemen tationTypes.Add (implementedTyp e)
baseType.Member s.Add(member)
Next
End Sub

Private Sub ImplementInterf aceMethods(ByVa l baseType As
CodeTypeDeclara tion, ByVal implementedType As Type)
Static void As Type = Type.GetType("S ystem.Void")
For Each [method] As MethodInfo In implementedType .GetMethods()
If Not [method].IsSpecialName Then
Dim member As New CodeMemberMetho d
member.Attribut es = MemberAttribute s.Public
member.Name = [method].Name
member.ReturnTy pe = New
CodeTypeReferen ce([method].ReturnType)
ImplementParame ters(member.Par ameters,
[method].GetParameters( ))
member.Implemen tationTypes.Add (implementedTyp e)
baseType.Member s.Add(member)
End If
Next
End Sub

Private Sub ImplementParame ters(ByVal outputParameter s As
CodeParameterDe clarationExpres sionCollection, ByVal inputParameters () As
ParameterInfo)
For Each parameter As ParameterInfo In inputParameters
Dim value As New CodeParameterDe clarationExpres sion
value.Name = parameter.Name
value.Type = New CodeTypeReferen ce(parameter.Pa rameterType)
outputParameter s.Add(value)
Next
End Sub

Private Function BuildClass(ByVa l ns As CodeNamespace, ByVal name As
String, ByVal baseType As Type) As CodeTypeDeclara tion
Dim type As New CodeTypeDeclara tion(name)
ns.Types.Add(ty pe)

type.BaseTypes. Add(baseType)

Return type
End Function

Private Sub GenerateCode(By Val unit As CodeCompileUnit , ByVal file As
String, ByVal provider As CodeDomProvider )
Dim output As New StreamWriter(fi le)
Dim generator As ICodeGenerator = provider.Create Generator()
Dim options As New CodeGeneratorOp tions
options.BlankLi nesBetweenMembe rs = True
options.Bracing Style = "C"

unit.UserData.A dd("AllowLateBo und", False)
unit.UserData.A dd("RequireVari ableDeclaration ", True)

Try
generator.Gener ateCodeFromComp ileUnit(unit, output, options)
Catch e As Exception
Debug.WriteLine (e, "GenerateCo de")
Finally
output.Flush()
output.Close()
provider.Dispos e()
End Try
End Sub

End Module

---x--- cut here ---x---

"Bill Rust" <n5****@communi ty.nospam> wrote in message
news:50******** *************** ***********@mic rosoft.com...
| Hi Jay,
|
| Thank you for your reply. I figured reflection could be used to
| accomplished this task, but I was trying to avoid coding it if the
capability
| was already available in the DTE. Since it is not, I would sure
appreciate
| any sample code you can provide.
|
| Best regards,
| Bill
|
| "Jay B. Harlow [MVP - Outlook]" wrote:
|
| > Bill,
| > In addition to Peter's comments.
| >
| > What are you using to generate the class itself?
| >
| > Have you considered using Reflection to read the definition of the
| > Interface, then adding those members to the code that you are creating?
| >
| > I will try to post an example of using Reflection to read the definition
of
| > an Interface to generate code later...
| >
| > Hope this helps
| > Jay
| >
| > "Bill Rust" <n5****@communi ty.nospam> wrote in message
| > news:34******** *************** ***********@mic rosoft.com...
| > | I've created an "Add Item" wizard for VB.NET 2003 that allows a user
to
| > add a
| > | specialized class that works with my application framework. In the
| > wizard,
| > | the user can select the interfaces they would like to support. During
the
| > | code generation phase, I add an "Implements Ixxx" for each interface
they
| > | select, but I've not yet figured out how to add the skeleton
| > implementation
| > | for those interfaces. Once the user opens the class in the VS IDE,
they
| > | can position the cursor after the interface name and hit return to
| > | auto-generate the implementation. Is there a way to programmaticall y
| > cause
| > | VB.NET to generate the skeleton implementation for these interfaces
using
| > the
| > | extensibility model?
| > |
| > | Thanks!
| > | Bill
| > |
| > |
| >
| >
| >

Nov 21 '05 #7
Bill,
| > The code for Properties & Methods work, however Events fail, so I'm not
sure
| > what the problem is. I'm checking into it. Cannot think of a workaround
| > right now.
Just realized: If events are important, using a CodeSnippet may be the
workaround, I don't have an example right now.

I'm going to try my routine in VS.NET 2005 to see if it has the same problem
with events.

Hope this helps
Jay

"Bill Rust" <n5****@communi ty.nospam> wrote in message
news:88******** *************** ***********@mic rosoft.com...
| Thanks, Jay. I'll give it a try :-)
|
| "Jay B. Harlow [MVP - Outlook]" wrote:
|
| > Bill,
| > Here is an example that uses Reflection & the Code Dom to implement an
| > interface.
| >
| > There seems to be a problem with the CodeMemberEvent .Implementation Types
| > member of the CodeDom. For example if I
| >
| > Implements System.Componen tModel.ICompone nt
| >
| >
| > My routine creates:
| >
| > Public Event Disposed As System.EventHan dler
| >
| > Instead of:
| >
| > Public Event Disposed As System.EventHan dler Implements
| > IComponent.Disp osed
| >
| > The code for Properties & Methods work, however Events fail, so I'm not
sure
| > what the problem is. I'm checking into it. Cannot think of a workaround
| > right now.
| >
| > You can use CodeTypeMember. Attributes to control the visibility of the
| > generated members. Or use PrivateImplemen tationType member of
| > CodeMemberEvent , CodeMemberPrope rty & CodeMemberMetho d to "hide" the
| > implementation of the methods...
| >
| > Hope this helps
| > Jay
| >
| > ---x--- cut here ---x---
| > Option Strict On
| > Option Explicit On
| >
| > Imports System.CodeDom
| > Imports System.CodeDom. Compiler
| >
| > Imports System.IO
| > Imports System.Reflecti on
| >
| > Public Module GenerateInterfa ce
| >
| > Public Sub Main()
| > Dim unit As New CodeCompileUnit
| >
| > Dim ns As New CodeNamespace(" Sample")
| > unit.Namespaces .Add(ns)
| >
| > Dim type As CodeTypeDeclara tion = BuildClass(ns, "BillRust",
| > GetType(Object) )
| >
| > ImplementInterf ace(type,
| > GetType(System. ComponentModel. IBindingList))
| >
| > GenerateCode(un it, "BillRust.v b", New VBCodeProvider)
| > End Sub
| >
| > Private Sub ImplementInterf ace(ByVal baseType As
CodeTypeDeclara tion,
| > ByVal implementedType As Type)
| > baseType.BaseTy pes.Add(New CodeTypeReferen ce(implementedT ype))
| >
| > ImplementInterf aceMembers(base Type, implementedType )
| >
| > For Each baseInterface As Type In
implementedType .GetInterfaces( )
| > ImplementInterf aceMembers(base Type, baseInterface)
| > Next
| >
| > End Sub
| >
| > Private Sub ImplementInterf aceMembers(ByVa l baseType As
| > CodeTypeDeclara tion, ByVal implementedType As Type)
| > ImplementInterf aceEvents(baseT ype, implementedType )
| > ImplementInterf aceProperties(b aseType, implementedType )
| > ImplementInterf aceMethods(base Type, implementedType )
| > End Sub
| >
| > Private Sub ImplementInterf aceEvents(ByVal baseType As
| > CodeTypeDeclara tion, ByVal implementedType As Type)
| > For Each [event] As EventInfo In implementedType .GetEvents()
| > Dim member As New CodeMemberEvent
| > member.Name = [event].Name
| > member.Attribut es = MemberAttribute s.Public
| > member.Type = New
CodeTypeReferen ce([event].EventHandlerTy pe)
| > member.Implemen tationTypes.Add (implementedTyp e)
| > baseType.Member s.Add(member)
| > Next
| > End Sub
| >
| > Private Sub ImplementInterf aceProperties(B yVal baseType As
| > CodeTypeDeclara tion, ByVal implementedType As Type)
| > For Each [property] As PropertyInfo In
| > implementedType .GetProperties( )
| > Dim member As New CodeMemberPrope rty
| > member.Name = [property].Name
| > member.Attribut es = MemberAttribute s.Public
| > member.HasGet = [property].CanRead
| > member.HasSet = [property].CanWrite
| > member.Type = New CodeTypeReferen ce([property].PropertyType)
| > ImplementParame ters(member.Par ameters,
| > [property].GetIndexParame ters())
| > member.Implemen tationTypes.Add (implementedTyp e)
| > baseType.Member s.Add(member)
| > Next
| > End Sub
| >
| > Private Sub ImplementInterf aceMethods(ByVa l baseType As
| > CodeTypeDeclara tion, ByVal implementedType As Type)
| > Static void As Type = Type.GetType("S ystem.Void")
| > For Each [method] As MethodInfo In implementedType .GetMethods()
| > If Not [method].IsSpecialName Then
| > Dim member As New CodeMemberMetho d
| > member.Attribut es = MemberAttribute s.Public
| > member.Name = [method].Name
| > member.ReturnTy pe = New
| > CodeTypeReferen ce([method].ReturnType)
| > ImplementParame ters(member.Par ameters,
| > [method].GetParameters( ))
| > member.Implemen tationTypes.Add (implementedTyp e)
| > baseType.Member s.Add(member)
| > End If
| > Next
| > End Sub
| >
| > Private Sub ImplementParame ters(ByVal outputParameter s As
| > CodeParameterDe clarationExpres sionCollection, ByVal inputParameters () As
| > ParameterInfo)
| > For Each parameter As ParameterInfo In inputParameters
| > Dim value As New CodeParameterDe clarationExpres sion
| > value.Name = parameter.Name
| > value.Type = New CodeTypeReferen ce(parameter.Pa rameterType)
| > outputParameter s.Add(value)
| > Next
| > End Sub
| >
| > Private Function BuildClass(ByVa l ns As CodeNamespace, ByVal name As
| > String, ByVal baseType As Type) As CodeTypeDeclara tion
| > Dim type As New CodeTypeDeclara tion(name)
| > ns.Types.Add(ty pe)
| >
| > type.BaseTypes. Add(baseType)
| >
| > Return type
| > End Function
| >
| > Private Sub GenerateCode(By Val unit As CodeCompileUnit , ByVal file
As
| > String, ByVal provider As CodeDomProvider )
| > Dim output As New StreamWriter(fi le)
| > Dim generator As ICodeGenerator = provider.Create Generator()
| > Dim options As New CodeGeneratorOp tions
| > options.BlankLi nesBetweenMembe rs = True
| > options.Bracing Style = "C"
| >
| > unit.UserData.A dd("AllowLateBo und", False)
| > unit.UserData.A dd("RequireVari ableDeclaration ", True)
| >
| > Try
| > generator.Gener ateCodeFromComp ileUnit(unit, output, options)
| > Catch e As Exception
| > Debug.WriteLine (e, "GenerateCo de")
| > Finally
| > output.Flush()
| > output.Close()
| > provider.Dispos e()
| > End Try
| > End Sub
| >
| > End Module
| >
| > ---x--- cut here ---x---
| >
| > "Bill Rust" <n5****@communi ty.nospam> wrote in message
| > news:50******** *************** ***********@mic rosoft.com...
| > | Hi Jay,
| > |
| > | Thank you for your reply. I figured reflection could be used to
| > | accomplished this task, but I was trying to avoid coding it if the
| > capability
| > | was already available in the DTE. Since it is not, I would sure
| > appreciate
| > | any sample code you can provide.
| > |
| > | Best regards,
| > | Bill
| > |
| > | "Jay B. Harlow [MVP - Outlook]" wrote:
| > |
| > | > Bill,
| > | > In addition to Peter's comments.
| > | >
| > | > What are you using to generate the class itself?
| > | >
| > | > Have you considered using Reflection to read the definition of the
| > | > Interface, then adding those members to the code that you are
creating?
| > | >
| > | > I will try to post an example of using Reflection to read the
definition
| > of
| > | > an Interface to generate code later...
| > | >
| > | > Hope this helps
| > | > Jay
| > | >
| > | > "Bill Rust" <n5****@communi ty.nospam> wrote in message
| > | > news:34******** *************** ***********@mic rosoft.com...
| > | > | I've created an "Add Item" wizard for VB.NET 2003 that allows a
user
| > to
| > | > add a
| > | > | specialized class that works with my application framework. In
the
| > | > wizard,
| > | > | the user can select the interfaces they would like to support.
During
| > the
| > | > | code generation phase, I add an "Implements Ixxx" for each
interface
| > they
| > | > | select, but I've not yet figured out how to add the skeleton
| > | > implementation
| > | > | for those interfaces. Once the user opens the class in the VS
IDE,
| > they
| > | > | can position the cursor after the interface name and hit return to
| > | > | auto-generate the implementation. Is there a way to
programmaticall y
| > | > cause
| > | > | VB.NET to generate the skeleton implementation for these
interfaces
| > using
| > | > the
| > | > | extensibility model?
| > | > |
| > | > | Thanks!
| > | > | Bill
| > | > |
| > | > |
| > | >
| > | >
| > | >
| >
| >
| >
Nov 21 '05 #8
Hi Bill,

Thanks for your quickly reply!

If you still have any concern, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
16573
by: Yudan YI \(OSU\) | last post by:
I want to generate random data from a normal distribution, while I checked the functions, and I found rand(), which returns a pseudorandom integer between zero and RAND_MAX. I am not sure how to use this function to generate my random data from a normal distribution. Thanks Yudan
2
2280
by: SalimShahzad | last post by:
Dear Gurus, i had written following codes to auto generate the next claim no Private Const strC = "GCT/02/J/" Private Sub Command1_Click() Dim stra, stre As String Dim intb, intd As Integer Dim strd As String stra = "200"
5
1427
by: Jeff Louie | last post by:
Can anyone explain why a interface method implementation using the fully qualified name cannot be public or protected? Sample below: public interface IDrawable { void DrawYourself(); } public interface IPositional { Point Position
20
4263
by: Ole Hanson | last post by:
I am accessing my database through an interface, to allow future substitution of the physical datastore - hence I would like to declare in my Interface that my DAL-objects implementing the interface and accessing the datastore MUST pass in a UserToken in the constructor of the object. Is this not possible? Am I forced to add the UserToken as a property on the object instead? /Ole
6
1945
by: Ricky W. Hunt | last post by:
It's dawning on my a lot of my problems with VB.NET is I'm still approaching it in the same way I've programmed since the late 70's. I've always been very structured, flow-charted everything, used subroutines, etc. Now I'm trying to study this new way and I'm getting some terms confused and can find no clear definition (some even overlap or use two different words for the same thing, even when they are actually different). I'm reading a...
0
333
by: Bill Rust | last post by:
I've created an "Add Item" wizard for VB.NET 2003 that allows a user to add a specialized class that works with my application framework. In the wizard, the user can select the interfaces they would like to support. During the code generation phase, I add an "Implements Ixxx" for each interface they select, but I've not yet figured out how to add the skeleton implementation for those interfaces. Once the user opens the class in the VS...
6
3497
by: | last post by:
Hi, can someone provide some advise on how to get around with using auto generated proxies? basically I already have the proxy classes, and they are used by other places. I'd like use these existing classes instead of having to generate another set of proxy classes, which are going to be very similar to my existing classes. any idea? thanks, -Jason
20
6087
by: Luc Kumps | last post by:
(Sorry about the previous post, it got transmitted before it was complete) We try to separate implementation and interface defintions, but we run into a problem. I hope the guru's can solve this, as we seem to lack only a single 'step' to have "full separation"... We have a first project, namespace Ninterface, that contains the interface definitions in class1_interface.cs, like this: namespace Ninterface { public interface IClass1{
10
6955
by: Sebastian | last post by:
Hi, I'm confronted with a problem that seems not to be solvable. In general: How can I override an interface member of my base class and call the overridden method from my derived class? This is my class: class RemoteXmlDataSource : System.Web.UI.WebControls.XmlDataSource And I want to override
0
9618
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10260
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9906
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6712
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.