ObservableProperty - IridiumIO/MVVM.VBSourceGenerators GitHub Wiki
Used to generate a Property
for the given private field that makes use of the MVVM Toolkit's ObservableObject
PropertyChanged
notifications.
This generated property will include several supporting Partial
methods that can be implemented if chosen. If you do not use these methods, the compiler will strip them out avoiding any runtime overhead.
[!IMPORTANT] Compared to CSharp, the field in VB.NET must be prefixed with an underscore ("_") or it will not work.
Supported on
- Fields
- Properties (VB.NET does not support partial properties)
- Classes
Requires
- Class must be partial
- Class must inherit from
ObservableObject
orObservableRecipient
- Class-level
<ObservableObject>
attribute is not supported yet
Usage
Given the annotated field like so:
Public Partial Class MyViewModel : Inherits ObservableObject
<ObservableProperty>
Private _firstName As String
End Class
The following code will be generated:
Public Property FirstName As String
Get
Return _firstName
End Get
Set(value As String)
If Global.System.Collections.Generic.EqualityComparer(Of String).Default.Equals(_firstName, value) Then Return
OnFirstNameChanging(value)
OnFirstNameChanging(Nothing, value)
OnPropertyChanging(NameOf(FirstName))
_firstName = value
OnFirstNameChanged(value)
OnFirstNameChanged(Nothing, value)
OnPropertyChanged(NameOf(FirstName))
OnPropertyChanged(NameOf(FullName))
End Set
End Property
Partial Private Sub OnFirstNameChanging(value As String): End Sub
Partial Private Sub OnFirstNameChanging(oldValue As String, newValue As String): End Sub
Partial Private Sub OnFirstNameChanged(value As String): End Sub
Partial Private Sub OnFirstNameChanged(oldValue As String, newValue As String): End Sub