The definition and implementation of a partial method are generally in separate files, which are created by using a partial class. Typically, the purpose of a partial method is to provide notification that something in the project has been changed.
In the following example, a partial method named OnNameChanged is developed and called. The method signature is defined in partial class Customer in file Customer.Designer.vb. The implementation is in partial class Customer in file Customer.vb, and an instance of Customer is created in a project that uses the class.
The result is a message box that contains the following message:
Name was changed to: Blue Yonder Airlines.
' File Customer.Designer.vb provides a partial class definition for
' Customer, which includes the signature for partial method
' OnNameChanged.
Partial Class Customer
Private _Name As String
Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
OnNameChanged()
End Set
End Property
' Definition of the partial method signature.
Partial Private Sub OnNameChanged()
End Sub
End Class
' In a separate file, a developer who wants to use the partial class
' and partial method fills in an implementation for OnNameChanged.
Partial Class Customer
' Implementation of the partial method.
Private Sub OnNameChanged()
MsgBox("Name was changed to " & Me.Name)
End Sub
End Class
Module Module1
Sub Main()
' Creation of cust will invoke the partial method.
Dim cust As New Customer With {.Name = "Blue Yonder Airlines"}
End Sub
End Module