Home All Groups Group Topic Archive Search About

Define a Default Implementation for an Interface?

Author
16 Sep 2006 9:37 PM
mark.milley@binaryswitch.com
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

Author
16 Sep 2006 10:14 PM
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


<mark.mil***@binaryswitch.com> wrote in message
Show quoteHide quote
news:1158442624.588124.276580@i42g2000cwa.googlegroups.com...
| 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
|