IridiumIO.MVVM.VBSourceGenerators 0.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package IridiumIO.MVVM.VBSourceGenerators --version 0.2.0
                    
NuGet\Install-Package IridiumIO.MVVM.VBSourceGenerators -Version 0.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="IridiumIO.MVVM.VBSourceGenerators" Version="0.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="IridiumIO.MVVM.VBSourceGenerators" Version="0.2.0" />
                    
Directory.Packages.props
<PackageReference Include="IridiumIO.MVVM.VBSourceGenerators" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add IridiumIO.MVVM.VBSourceGenerators --version 0.2.0
                    
#r "nuget: IridiumIO.MVVM.VBSourceGenerators, 0.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package IridiumIO.MVVM.VBSourceGenerators@0.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=IridiumIO.MVVM.VBSourceGenerators&version=0.2.0
                    
Install as a Cake Addin
#tool nuget:?package=IridiumIO.MVVM.VBSourceGenerators&version=0.2.0
                    
Install as a Cake Tool

MVVM.VBSourceGenerators

The CommunityToolkit.MVVM source generators only work in C#. This package augments the toolkit to allow some of the generators to work for VB.NET.

Working

  • <ObservableProperty> attribute generates a public property with change notification.
  • <NotifyPropertyChangedFor(NameOf(T))> attribute generates a property with change notification for existing properties.
  • <RelayCommand>
    • Can decorate Sub, Async Sub, or Async Function
    • Supports CanExecute callback functionality
    • Supports passing a parameter to the command

Planned

  • <RelayCommand>
    • Passing cancellation tokens
  • NotifyCanExecuteChangedFor(NameOf(T))

Installation

  1. Add the NuGet package for MVVM.VBSourceGenerators to your VB.NET project:
    dotnet add package IridiumIO.MVVM.VBSourceGenerators
    
  2. Ensure that you also reference CommunityToolkit.MVVM in your project.

ObservableProperty Usage

  1. In your VB.NET ViewModel, use the [ObservableProperty] attribute as you would in C#
  2. Make sure your fields follow the naming convention of starting with an underscore (e.g., _name).
  3. You can then use the generated Uppercase property Name in your code.

Example 1:

Imports CommunityToolkit.Mvvm.ComponentModel

Partial Public Class MyViewModel
    Inherits ObservableObject

    <ObservableProperty>
    Private _name As String
End Class

 

Example 2: Including NotifyPropertyChangedFor

Imports CommunityToolkit.Mvvm.ComponentModel

Partial Public Class PersonViewModel
    Inherits ObservableObject

    <ObservableProperty>
    <NotifyPropertyChangedFor(NameOf(FullName))>
    Private _firstName As String

    <ObservableProperty>
    <NotifyPropertyChangedFor(NameOf(FullName))>
    Private _lastName As String

    Public ReadOnly Property FullName As String
        Get
            Return $"{FirstName} {LastName}"
        End Get
    End Property

End Class

RelayCommand Usage

  1. In your VB.NET ViewModel, use the [RelayCommand] attribute as you would in C# on a method.
Examples:
Imports CommunityToolkit.Mvvm.ComponentModel

Partial Public Class MyViewModel
    Inherits ObservableObject

    <RelayCommand>
    Private Sub Save()
        ' Save logic here
    End Sub

    <RelayCommand>
    Private Sub SelectItem(item As String)
        ' Logic to select an item
    End Sub

    <RelayCommand>
    Private Async Function LoadDataAsync() As Task
        ' Load data logic here
        Await Task.Delay(1000) ' Simulating async work
    End Function

End Class

 

Example 2: Including CanExecute callback

By creating a function that returns a Boolean and prefixing it with Can, you can control whether the command can execute.

Imports CommunityToolkit.Mvvm.ComponentModel

Partial Public Class PersonViewModel
    Inherits ObservableObject

    <RelayCommand>
    Private Sub SaveData()
        ' Logic to save data
    End Sub

    Private Function CanSaveData() As Boolean
        ' Logic to determine if saving is allowed
         Return MyData.Count > 0
    End Function

End Class
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.6.1 161 7/9/2025
0.6.0 150 7/8/2025
0.5.0 140 7/6/2025
0.4.0 79 7/5/2025
0.3.0 99 7/4/2025
0.2.0 142 7/3/2025
0.1.0 142 7/3/2025

Added Support for RelayCommand attributes on methods