2013-07-05 111 views
2

我在.NET框架中看到過一些情況,當您實現一個接口時,Visual Studio會生成註釋(以及其他好的東西,如區域)。向接口添加註釋

一個很好的例子是IDisposable。當你實現它時,Visual Studio生成以下代碼塊:

#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 

這是我能在自己的代碼中做的事嗎?如果是這樣,怎麼樣?我想在接口的方法中添加一些註釋,告訴實現者該方法的一般用途是什麼。

+1

[VB.net:Custom'TODO:List on a Interface]的可能重複(http://stackoverflow.com/questions/2884036/vb-net-custom-todo-list-on-an-interface) –

回答

0

我不確定這是否是100%你問的,但在這裏。

你上面的方法定義類型「」」

編輯擴大了出成片的XML的用來驅動智能感知當使用該方法。

Private Sub Import(ByVal ImportFileName As String, ByRef OutFileName As String) 

成爲

''' <summary> 
''' Imports data from import file into Output File 
''' </summary> 
''' <param name="ImportFileName">the fully qualified path to the import file</param> 
''' <param name="OutFileName">the fully qualified path for the output file</param> 
''' <remarks>all the widgets need to be thoroughly castigated</remarks> 
Private Sub Import(ByVal ImportFileName As String, ByRef OutFileName As String) 

而每當這種導入方法是用來提供的線索都沿着參數的名稱。

+0

這可能是我所能得到的最接近的,但我真的正在尋找一種方法來爲我的界面提供內聯代碼文檔。只有編寫實現的程序員才能看到它們,而不是每個使用它的人。 –

+0

如果你曾經在VB中編寫過實現'IDisposable'的類,你就會明白我的意思。只要添加界面,就會得到一個默認實現,其中包含TODO註釋。這正是我想要做的事情。 –

+0

我已經使用了IDisposable接口,並確切地知道你的意思。但根據上面的鏈接問題,IDisposable的可愛TODO內容被硬編碼到VS編輯器中。你最好的課程是有片段, –