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

这是我可以在自己的代码中做的事情吗?如果是这样,怎么做?我想在我的接口方法中添加一些注释,告诉实现者该方法的一般用途是什么。

4

1 回答 1

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)

并且每当使用此 Import 方法时,所提供的提示都会与参数名称一起显示。

于 2013-07-18T10:17:19.777 回答