Define a Default Implementation for an Interface?

M

mark.milley

Hi all -

Okay, here's a question for all you MVPs out there--I'd like to define
a default implementation for an interface. While I understand that when
you implement a interface, empty routines are created for you (thanks
MS), I'd like to take it one step further and add in comments, and
maybe an If block.

Microsoft does this; for example, implement iDisposable; all of the
code and comments below are created. I'd love to do the same thing. Any
suggestions?

Thanks,

- M

Private disposedValue As Boolean = False ' To detect
redundant calls

' IDisposable
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If Not Me.disposedValue Then
If disposing Then
' TODO: free unmanaged resources when explicitly
called
End If

' TODO: free shared unmanaged resources
End If
Me.disposedValue = True
End Sub

#Region " IDisposable Support "
' This code added by Visual Basic to correctly implement the
disposable pattern.
Public Sub Dispose() Implements IDisposable.Dispose
' Do not change this code. Put cleanup code in
Dispose(ByVal disposing As Boolean) above.
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
 
J

Jay B. Harlow [MVP - Outlook]

Mark,
Do you want to do this for a specific interface or any interface in general?

For a specific interface I would consider using a Code Snippet that had the
"default implementation" for that interface. Then I would make a point to
use the Code Snippet when implementing the interface...

For any interface in general I would consider writing a macro/program that
created the "default implementation" for an interface...

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| Hi all -
|
| Okay, here's a question for all you MVPs out there--I'd like to define
| a default implementation for an interface. While I understand that when
| you implement a interface, empty routines are created for you (thanks
| MS), I'd like to take it one step further and add in comments, and
| maybe an If block.
|
| Microsoft does this; for example, implement iDisposable; all of the
| code and comments below are created. I'd love to do the same thing. Any
| suggestions?
|
| Thanks,
|
| - M
|
| Private disposedValue As Boolean = False ' To detect
| redundant calls
|
| ' IDisposable
| Protected Overridable Sub Dispose(ByVal disposing As Boolean)
| If Not Me.disposedValue Then
| If disposing Then
| ' TODO: free unmanaged resources when explicitly
| called
| End If
|
| ' TODO: free shared unmanaged resources
| End If
| Me.disposedValue = True
| End Sub
|
| #Region " IDisposable Support "
| ' This code added by Visual Basic to correctly implement the
| disposable pattern.
| Public Sub Dispose() Implements IDisposable.Dispose
| ' Do not change this code. Put cleanup code in
| Dispose(ByVal disposing As Boolean) above.
| Dispose(True)
| GC.SuppressFinalize(Me)
| End Sub
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top