How can I copy the IDisposable interface "automatic" code

Thierry Savard

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 ...

Scott Chamberlain

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.

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can i dispose IDisposable when it is declared in a parameter?

From Dev

How can I DRY out this F# code? (Fluent Interface)

From Dev

How can I override this method in this interface (see code)?

From Dev

How can I set up wai-handler-devel with Scotty to have automatic code reloading?

From Dev

How can I get a query from web interface, use it in a python code and then read the result in a perl code?

From Java

How can IDisposable field be null here?

From Dev

How can I select and copy a few lines of code while using a command line OS?

From Dev

How can I copy the hex color code of whatever pixel my mouse is hovering over?

From Dev

How to implement IDisposable interface in a class inherited from SocketAsyncEventArgs

From Java

Proper use of the IDisposable interface

From Dev

async/await and the IDisposable interface

From Dev

Collection class and IDisposable interface

From Dev

How can I copy String or str

From Dev

How can I copy a text file into another?

From Dev

How can I copy an IDENTITY field?

From Java

How can I copy a Python string?

From Dev

How can I use the FileSystemObject to "Copy and rename"

From Dev

how can i copy folders, subfolders and their files?

From Dev

How can I copy files which is not exists?

From Dev

How can I "copy as curl" in Safari?

From Dev

How can i copy this cells as this order?

From Dev

How can I do a "copy if changed" operation?

From Dev

How can I copy the text of a Button in the clipboard?

From Dev

How can I copy System Info to clipboard?

From Dev

How can I copy a text file into another?

From Dev

Problem : how can I copy/paste this in vim?

From Dev

how can i copy file in data directory

From Dev

How can I copy directory itself with attributes?

From Dev

How can I deep copy in typescript

Related Related

  1. 1

    How can i dispose IDisposable when it is declared in a parameter?

  2. 2

    How can I DRY out this F# code? (Fluent Interface)

  3. 3

    How can I override this method in this interface (see code)?

  4. 4

    How can I set up wai-handler-devel with Scotty to have automatic code reloading?

  5. 5

    How can I get a query from web interface, use it in a python code and then read the result in a perl code?

  6. 6

    How can IDisposable field be null here?

  7. 7

    How can I select and copy a few lines of code while using a command line OS?

  8. 8

    How can I copy the hex color code of whatever pixel my mouse is hovering over?

  9. 9

    How to implement IDisposable interface in a class inherited from SocketAsyncEventArgs

  10. 10

    Proper use of the IDisposable interface

  11. 11

    async/await and the IDisposable interface

  12. 12

    Collection class and IDisposable interface

  13. 13

    How can I copy String or str

  14. 14

    How can I copy a text file into another?

  15. 15

    How can I copy an IDENTITY field?

  16. 16

    How can I copy a Python string?

  17. 17

    How can I use the FileSystemObject to "Copy and rename"

  18. 18

    how can i copy folders, subfolders and their files?

  19. 19

    How can I copy files which is not exists?

  20. 20

    How can I "copy as curl" in Safari?

  21. 21

    How can i copy this cells as this order?

  22. 22

    How can I do a "copy if changed" operation?

  23. 23

    How can I copy the text of a Button in the clipboard?

  24. 24

    How can I copy System Info to clipboard?

  25. 25

    How can I copy a text file into another?

  26. 26

    Problem : how can I copy/paste this in vim?

  27. 27

    how can i copy file in data directory

  28. 28

    How can I copy directory itself with attributes?

  29. 29

    How can I deep copy in typescript

HotTag

Archive