问题描述
当你有一个实现IDisposable的类并且在IDisposable之后按下return时,IDE会在类中添加一堆代码,如: -
When you have a class that implements IDisposable and you press return after IDisposable, the IDE adds a load of code into the class like:-
#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.
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(disposing As Boolean) above.
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
#End Region
有什么方法可以获得类似的行为我自己构建的界面?
注意 - 我不想对IDisposable本身做任何事情。我只想对我的接口做IDE用IDisposable做的事情 - 当我在Implements Disposable(评论,区域等)之后点击返回时,所有上述内容都由IDE输入 - 我希望我的界面也能这样做因此,当开发人员实现我的界面时,可以输入使用提示。
注2:好的 - 我决定使用代码片段相反 - 从开发人员的角度来看也很容易。
is there any way to get a similar behaviour with my own built interfaces?
Note - I don't want to do anything with IDisposable itself. I just want to do to my interfaces what the IDE does with IDisposable - all of the above is put in by the IDE when I hit return after "Implements Disposable" (comments , region etc.) - I want my interface to do the same so that usage hints can be put in when a developer implements my interface.
Note 2: OK - I have decided to use code snippets instead - it is just as easy from the developer point of view.
推荐答案
这篇关于让我的界面像IDisposable一样添加额外的样板魔术的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!