ViewBaseGenerator 1.7.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package ViewBaseGenerator --version 1.7.2                
NuGet\Install-Package ViewBaseGenerator -Version 1.7.2                
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="ViewBaseGenerator" Version="1.7.2">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ViewBaseGenerator --version 1.7.2                
#r "nuget: ViewBaseGenerator, 1.7.2"                
#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.
// Install ViewBaseGenerator as a Cake Addin
#addin nuget:?package=ViewBaseGenerator&version=1.7.2

// Install ViewBaseGenerator as a Cake Tool
#tool nuget:?package=ViewBaseGenerator&version=1.7.2                

ViewBaseGenerator

The main purpose of the generator is to avoid boilerplate code in the code-behind views files, like this:

public abstract partial class PreviewDropViewBase
: ReactiveUI.Uno.ReactiveUserControl<Ratbuddyssey.ViewModels.PreviewDropViewModel>
{
}

public partial class MainView
{
    public MainView()
    {
        InitializeComponent();

        _ = this.WhenActivated(disposables =>
        {
            DataContext = ViewModel;
        });
    }
}

At the same time, the generator supports the ability to add your code anywhere through the definition of partial methods for special cases:

public partial class MainView
{
    partial void BeforeInitializeComponent();
    partial void AfterInitializeComponent();

    partial void AfterWhenActivated(CompositeDisposable disposables);

    public MainView()
    {
        BeforeInitializeComponent();

        InitializeComponent();

        AfterInitializeComponent();

        _ = this.WhenActivated(disposables =>
        {
            DataContext = ViewModel;

            if (ViewModel == null)
            {
                return;
            }

            AfterWhenActivated(disposables);
        });
    }
}

I also recommend not deleting .xaml.cs files, but leaving them empty like this:

namespace YourNamespace.Views;

public partial class MainView
{
}

Nuget

NuGet

Install-Package ViewBaseGenerator

WPF/UWP/WinUI

  <PropertyGroup>
    <ViewBaseGenerator_Namespace>YourNamespace.Views</ViewBaseGenerator_Namespace>
  </PropertyGroup

  <ItemGroup Label="View Constructors">
    <AdditionalFiles Include="Views\**\*.xaml" ViewBaseGenerator_GenerateConstructor="True" ViewBaseGenerator_SetReactiveUIDataContext="True" />
  </ItemGroup>

  <ItemGroup Label="ViewBase">
    <AdditionalFiles Include="Views\**\*.xaml.cs" ViewBaseGenerator_BaseClass="ReactiveUI.Uno.ReactiveUserControl" ViewBaseGenerator_ViewModelNamespace="YourNamespace.ViewModels" />
  </ItemGroup>

Although ReactiveUI is supported, you can also use the generator without it, just to get rid of the InitializeComponent() constructors. In this case, you need code like:

  <PropertyGroup>
    <ViewBaseGenerator_Namespace>YourNamespace.Views</ViewBaseGenerator_Namespace>
  </PropertyGroup

  <ItemGroup Label="View Constructors">
    <AdditionalFiles Include="Views\**\*.xaml" ViewBaseGenerator_GenerateConstructor="True" />
  </ItemGroup>

Uno (projects besides UWP/WinUI)

Uno uses Source Generators and there is currently no way to use the output of one generator in another. Therefore, the solution is somewhat more complicated:

  1. Create new project like this:
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>netstandard2.0;net6.0-android;net6.0-ios;net6.0-macos;net6.0-maccatalyst</TargetFrameworks>
  </PropertyGroup>

  <PropertyGroup>
    <ViewBaseGenerator_Namespace>YourNamespace.Views</ViewBaseGenerator_Namespace>
  </PropertyGroup>

  <ItemGroup Label="ViewBase">
    <AdditionalFiles Include="..\..\shared\YourNamespace.Shared\Views\**\*.xaml.cs" ViewBaseGenerator_BaseClass="ReactiveUI.Uno.ReactiveUserControl" ViewBaseGenerator_ViewModelNamespace="YourNamespace.ViewModels" Visible="False" />
    <AdditionalFiles Remove="..\..\shared\YourNamespace.Shared\Views\Navigation\MainView.xaml.cs" />
    <AdditionalFiles Include="..\..\shared\YourNamespace.Shared\Views\Navigation\MainView.xaml.cs" ViewBaseGenerator_BaseClass="ReactiveUI.Uno.ReactivePage" ViewBaseGenerator_ViewModelNamespace="YourNamespace.ViewModels" Visible="False" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="ViewBaseGenerator" Version="1.3.8">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>

  <ItemGroup>
    
    <PackageReference Include="ReactiveUI.Uno" Version="16.2.6" />
  </ItemGroup>

  <ItemGroup>
    
    <ProjectReference Include="..\YourNamespace.Core\YourNamespace.Core.csproj" />
  </ItemGroup>
	
</Project>
  1. Add this project reference to your apps.

Contacts

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

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
1.15.0 380 3/10/2023
1.14.0 295 2/6/2023
1.13.0 621 8/22/2022
1.12.0 386 8/22/2022
1.11.3 385 8/22/2022
1.11.2 409 8/22/2022
1.11.1 416 8/22/2022
1.11.0 401 8/22/2022
1.10.0 475 7/20/2022
1.9.0 439 7/13/2022
1.8.3 486 7/13/2022
1.8.2 452 7/8/2022
1.8.1 406 7/8/2022
1.8.0 410 7/8/2022
1.7.3 432 7/8/2022
1.7.2 361 7/8/2022
1.7.1 389 7/8/2022
1.7.0 378 7/8/2022
1.6.2 423 6/30/2022
1.6.1 400 6/28/2022
1.6.0 397 6/28/2022
1.5.1 418 6/28/2022
1.5.0 416 6/27/2022
1.4.0 408 6/12/2022
1.3.25 403 5/25/2022
1.3.24 440 5/18/2022
1.3.23 434 5/18/2022
1.3.22 462 3/23/2022
1.3.21 991 10/28/2021
1.3.20 339 10/28/2021
1.3.17 305 10/28/2021
1.3.16 321 10/28/2021
1.3.15 359 10/28/2021
1.3.14 357 10/28/2021
1.3.13 312 10/28/2021
1.3.12 311 10/28/2021
1.3.11 299 10/28/2021
1.3.10 362 10/28/2021
1.3.9 441 10/20/2021
1.3.8 426 10/17/2021
1.3.7 346 10/17/2021
1.3.6 405 10/17/2021
1.2.5 360 10/17/2021
1.2.4 380 10/17/2021

⭐ Last 10 features:
Added ability to setup ViewModel in constructor generators.
Added ViewBaseGenerator_CreateReactiveUIWhenActivated.
Changed hint names.
To ConventionalCommitsGitInfo.
Updated to latest H.Generators.Extensions.
To H.Generators.Tests.Extensions.
Updated H.Generators.Extensions.
To IIncrementalGenerator.
Added ContinuousIntegrationBuild.
Deleted deffered generators.
🐞 Last 10 bug fixes:
Fixed PropertyMetadata bug.
Added GenerateViewBase setting.
Fixed constructor generation.
Fixed bug with order of ReactiveUI properties.
Fixed empty lines in generated code.
Fixed tests.
Fixed endings bug.
Fixed GenerateConstructor IsDeffered bug.
Fixed DefferedConstructor generation.
Fixed constructor class name bug.