By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,370 Members | 1,534 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,370 IT Pros & Developers. It's quick & easy.

Define a Default Implementation for an Interface?

P: n/a
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

Sep 16 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
<ma*********@binaryswitch.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.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
|
Sep 16 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.