2013-07-05 119 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编辑器中。你最好的课程是有片段, –