ViewBaseGenerator 1.6.2
See the version list below for details.
dotnet add package ViewBaseGenerator --version 1.6.2
NuGet\Install-Package ViewBaseGenerator -Version 1.6.2
<PackageReference Include="ViewBaseGenerator" Version="1.6.2"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add ViewBaseGenerator --version 1.6.2
#r "nuget: ViewBaseGenerator, 1.6.2"
// Install ViewBaseGenerator as a Cake Addin #addin nuget:?package=ViewBaseGenerator&version=1.6.2 // Install ViewBaseGenerator as a Cake Tool #tool nuget:?package=ViewBaseGenerator&version=1.6.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
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:
- 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>
- Add this project reference to your apps.
Contacts
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 | 427 | 3/10/2023 |
1.14.0 | 332 | 2/6/2023 |
1.13.0 | 659 | 8/22/2022 |
1.12.0 | 417 | 8/22/2022 |
1.11.3 | 420 | 8/22/2022 |
1.11.2 | 443 | 8/22/2022 |
1.11.1 | 451 | 8/22/2022 |
1.11.0 | 432 | 8/22/2022 |
1.10.0 | 508 | 7/20/2022 |
1.9.0 | 479 | 7/13/2022 |
1.8.3 | 521 | 7/13/2022 |
1.8.2 | 489 | 7/8/2022 |
1.8.1 | 454 | 7/8/2022 |
1.8.0 | 446 | 7/8/2022 |
1.7.3 | 467 | 7/8/2022 |
1.7.2 | 396 | 7/8/2022 |
1.7.1 | 420 | 7/8/2022 |
1.7.0 | 418 | 7/8/2022 |
1.6.2 | 456 | 6/30/2022 |
1.6.1 | 434 | 6/28/2022 |
1.6.0 | 431 | 6/28/2022 |
1.5.1 | 451 | 6/28/2022 |
1.5.0 | 449 | 6/27/2022 |
1.4.0 | 442 | 6/12/2022 |
1.3.25 | 435 | 5/25/2022 |
1.3.24 | 472 | 5/18/2022 |
1.3.23 | 470 | 5/18/2022 |
1.3.22 | 497 | 3/23/2022 |
1.3.21 | 1,025 | 10/28/2021 |
1.3.20 | 371 | 10/28/2021 |
1.3.17 | 337 | 10/28/2021 |
1.3.16 | 355 | 10/28/2021 |
1.3.15 | 394 | 10/28/2021 |
1.3.14 | 387 | 10/28/2021 |
1.3.13 | 344 | 10/28/2021 |
1.3.12 | 341 | 10/28/2021 |
1.3.11 | 330 | 10/28/2021 |
1.3.10 | 397 | 10/28/2021 |
1.3.9 | 474 | 10/20/2021 |
1.3.8 | 458 | 10/17/2021 |
1.3.7 | 381 | 10/17/2021 |
1.3.6 | 441 | 10/17/2021 |
1.2.5 | 396 | 10/17/2021 |
1.2.4 | 416 | 10/17/2021 |
⭐ Last 10 features:
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.
Added GeneratorBase.AddSource.
🐞 Last 10 bug fixes:
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.
Fixed required BaseClass bug.
Fixed tests.