ViewBaseGenerator 1.5.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package ViewBaseGenerator --version 1.5.0
                    
NuGet\Install-Package ViewBaseGenerator -Version 1.5.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="ViewBaseGenerator" Version="1.5.0">
  <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.
<PackageVersion Include="ViewBaseGenerator" Version="1.5.0" />
                    
Directory.Packages.props
<PackageReference Include="ViewBaseGenerator">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
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 ViewBaseGenerator --version 1.5.0
                    
#r "nuget: ViewBaseGenerator, 1.5.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 ViewBaseGenerator@1.5.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=ViewBaseGenerator&version=1.5.0
                    
Install as a Cake Addin
#tool nuget:?package=ViewBaseGenerator&version=1.5.0
                    
Install as a Cake Tool

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 488 3/10/2023
1.14.0 384 2/6/2023
1.13.0 716 8/22/2022
1.12.0 476 8/22/2022
1.11.3 477 8/22/2022
1.11.2 502 8/22/2022
1.11.1 509 8/22/2022
1.11.0 491 8/22/2022
1.10.0 570 7/20/2022
1.9.0 541 7/13/2022
1.8.3 585 7/13/2022
1.8.2 552 7/8/2022
1.8.1 515 7/8/2022
1.8.0 509 7/8/2022
1.7.3 529 7/8/2022
1.7.2 460 7/8/2022
1.7.1 483 7/8/2022
1.7.0 481 7/8/2022
1.6.2 517 6/30/2022
1.6.1 495 6/28/2022
1.6.0 493 6/28/2022
1.5.1 514 6/28/2022
1.5.0 513 6/27/2022
1.4.0 505 6/12/2022
1.3.25 502 5/25/2022
1.3.24 538 5/18/2022
1.3.23 536 5/18/2022
1.3.22 567 3/23/2022
1.3.21 1,099 10/28/2021
1.3.20 447 10/28/2021
1.3.17 410 10/28/2021
1.3.16 431 10/28/2021
1.3.15 469 10/28/2021
1.3.14 462 10/28/2021
1.3.13 419 10/28/2021
1.3.12 417 10/28/2021
1.3.11 404 10/28/2021
1.3.10 474 10/28/2021
1.3.9 549 10/20/2021
1.3.8 531 10/17/2021
1.3.7 455 10/17/2021
1.3.6 514 10/17/2021
1.2.5 475 10/17/2021
1.2.4 490 10/17/2021

⭐ Last 10 features:
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.
Added GeneratorBase.AddSource.
Added generation only if any.
🐞 Last 10 bug fixes:
Fixed tests.
Fixed endings bug.
Fixed GenerateConstructor IsDeffered bug.
Fixed DefferedConstructor generation.
Fixed constructor class name bug.
Fixed required BaseClass bug.
Fixed tests.
Fixed ci.