How to implement default methods for an interface?

When creating a new class in .Net, if I declare it "Implements IDisposable" and press enter, I see that Visual Studio adds, in its methods and functions, already existing ones filled to my class. When I try to do this with my interfaces, it creates empty methods and functions .

Is there a way to provide standard methods and functions for my method?

I searched for the link but it didn't solve my problem.

An example implementation I'm looking for:

#Region "IDisposable Support"
    Private disposedValue As Boolean ' To detect redundant calls

    ' IDisposable
    Protected Overridable Sub Dispose(ByVal disposing As Boolean)
        If Not Me.disposedValue Then
            If disposing Then
                ' TODO: dispose managed state (managed objects).
            End If

            ' TODO: free unmanaged resources (unmanaged objects) and override Finalize() below.
            ' TODO: set large fields to null.
        End If
        Me.disposedValue = True
    End Sub

    ' TODO: override Finalize() only if Dispose(ByVal disposing As Boolean) above has code to free unmanaged resources.
    'Protected Overrides Sub Finalize()
    '    ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
    '    Dispose(False)
    '    MyBase.Finalize()
    'End Sub

    ' 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
#End Region

      

Greetings in advance.

Further exploration of what I'm looking for:

Suppose the following interface

enter image description here

Here's what's going on and what I'm looking for:

enter image description here

+3


source to share


2 answers


He knows how to tweak the base implementation IDisposable

, as there is a common pattern that you should follow.

But how could he know about how to implement his interfaces? So you end up with empty methods that you need to complete.



Your closest bet is to customize the snippet and paste this rather than let visual studio add unrealized members.

0


source


What I can think of is create my own item template, which can be selected from the Add New Item dialog box. You can change the Refactoring pattern, but that will change all interface implementations. Element templating is discussed here:   http://msdn.microsoft.com/en-us/library/tsyyf0yh.aspx



0


source







All Articles