I'm looking for a way to do interface in a similar way the IDisposable interface is done : when you implement it, the code appears with part of the methods already written down.
#Region "IDisposable Support"
Private disposedValue As Boolean ' To detect redundant calls
' IDisposable
Protected Overridable Sub Dispose(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.
... etc
Situation : I have a huge program with alot of small classes. Some of those classes have data, and I use a binary-serialiser to store the data. I created an interface ISave for this. It works, but I have to redefine the method Save() and the properties in each of those classes. Which ends up with alot of very very very similar code in each of those class, with only minor differences ( 1 cast, 1 or 1 extension name )
I used alot of different interface which could benefit from this ... if I make a little change somewhere in an interface, I end up with 90+ errors I have to arrange manually ... its getting painfully slow.
is there a way to write down my interface and leave a blank spot like way the Idisposable interface ?
EDIT :
I dont want to copy the Idisposable stuff. I want only to find out how to make the pre-defined code appears ...
I wrote down :
Public Class XYZ
Implements ISave()
and when I click enter, I want the region to appears in my class at the bottom, as well as my Save() method wich would be all written up, aside from 1 minor detail I could left blank to change, but the function would be written down elsewhere ... something like this pseudo-code :
#Region "ISave Interface automatic code"
Public sub Save()
'fill out the blank yourself'
If not Io.File.Exist( BLANKSPACE ) then
... code to create the file and save it
end if
End sub
#end Region
so I wont have to go in each of my 90 class and write it down manually myself ...
What you are looking for is called Code Snippets. The exact steps to do it is too long to explain here, but the MSDN has good step by step documentation on how to create them.
If you don't want to create them by hand there are 3rd party tools like Snippet Editor to help make Code Snippets easier to create.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments