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.
#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 459 3/10/2023
1.14.0 361 2/6/2023
1.13.0 689 8/22/2022
1.12.0 448 8/22/2022
1.11.3 450 8/22/2022
1.11.2 474 8/22/2022
1.11.1 482 8/22/2022
1.11.0 463 8/22/2022
1.10.0 542 7/20/2022
1.9.0 512 7/13/2022
1.8.3 556 7/13/2022
1.8.2 524 7/8/2022
1.8.1 486 7/8/2022
1.8.0 480 7/8/2022
1.7.3 499 7/8/2022
1.7.2 432 7/8/2022
1.7.1 455 7/8/2022
1.7.0 452 7/8/2022
1.6.2 489 6/30/2022
1.6.1 467 6/28/2022
1.6.0 465 6/28/2022
1.5.1 486 6/28/2022
1.5.0 484 6/27/2022
1.4.0 477 6/12/2022
1.3.25 472 5/25/2022
1.3.24 509 5/18/2022
1.3.23 506 5/18/2022
1.3.22 537 3/23/2022
1.3.21 1,069 10/28/2021
1.3.20 417 10/28/2021
1.3.17 381 10/28/2021
1.3.16 401 10/28/2021
1.3.15 439 10/28/2021
1.3.14 432 10/28/2021
1.3.13 390 10/28/2021
1.3.12 388 10/28/2021
1.3.11 375 10/28/2021
1.3.10 443 10/28/2021
1.3.9 518 10/20/2021
1.3.8 501 10/17/2021
1.3.7 425 10/17/2021
1.3.6 485 10/17/2021
1.2.5 443 10/17/2021
1.2.4 461 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.