SourceCrafter.ViewModelGenerator
0.23.233.61
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package SourceCrafter.ViewModelGenerator --version 0.23.233.61
NuGet\Install-Package SourceCrafter.ViewModelGenerator -Version 0.23.233.61
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="SourceCrafter.ViewModelGenerator" Version="0.23.233.61" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SourceCrafter.ViewModelGenerator --version 0.23.233.61
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SourceCrafter.ViewModelGenerator, 0.23.233.61"
#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 SourceCrafter.ViewModelGenerator as a Cake Addin #addin nuget:?package=SourceCrafter.ViewModelGenerator&version=0.23.233.61 // Install SourceCrafter.ViewModelGenerator as a Cake Tool #tool nuget:?package=SourceCrafter.ViewModelGenerator&version=0.23.233.61
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
✨ SourceCrafter.ViewModelGenerator: Simple partial classes for observable view models
Given the following spec interface
public enum Role
{
Admin,
Moderator,
Guest,
User
}
[ObservableModel]
public interface IUser
{
string FirstName { get; set; }
[Ignore]
string? LastName { get; set; }
int Age { get; set; }
bool CanDrink { get; set; }
string Name => $"{FirstName} {LastName}".Trim();
bool IsUnder18
{
get => Age >= 18;
set
{
Age = value ? 18 : 17;
CanDrink = !IsUnder18;
}
}
AsyncRelayCommand<Role> AddParentCommand { get; }
}
should generates the following view model class (based on the previous definition example):
public partial class User : ViewModelBase, IUser
{
private string
_firstName;
private int
_age;
private bool
_canDrink;
private AsyncRelayCommand<Role>
_addParentCommand;
private static readonly PropertyChangedEventArgs
_nameChangedEvtArg = new("Name"),
_isUnder18ChangedEvtArg = new("IsUnder18"),
_firstNameChangedEvtArg = new("FirstName"),
_ageChangedEvtArg = new("Age"),
_canDrinkChangedEvtArg = new("CanDrink");
public string Name => $"{FirstName} {LastName}".Trim();
public bool IsUnder18 {
get => Age >= 18;
set {
Age = value ? 18 : 17;
if (IsUnder18) CanDrink = true; else CanDrink = false;
OnPropertyChanged(_isUnder18ChangedEvtArg);
}
}
public string FirstName
{
get => _firstName;
set {
if(value == _firstName)
return;
_firstName = value;
OnPropertyChanged(_firstNameChangedEvtArg);
OnPropertyChanged(_nameChangedEvtArg);
}
}
public string? LastName { get; set; }
public int Age
{
get => _age;
set {
if(value == _age)
return;
_age = value;
OnPropertyChanged(_ageChangedEvtArg);
OnPropertyChanged(_isUnder18ChangedEvtArg);
}
}
public bool CanDrink
{
get => _canDrink;
set {
if(value == _canDrink)
return;
_canDrink = value;
OnPropertyChanged(_canDrinkChangedEvtArg);
OnPropertyChanged(_isUnder18ChangedEvtArg);
}
}
public AsyncRelayCommand<Role> AddParentCommand => _addParentCommand ??= new AsyncRelayCommand<Role>(ExecuteAddParentAsync, CanExecuteAddParent, AsyncRelayCommandOptions.None);
private partial bool CanExecuteAddParent(Role parameter);
private partial Task ExecuteAddParentAsync(Role parameter);
}
And you will have to complement it with commands methods definition
public partial class User
{
private partial bool CanExecuteAddParent(Role parameter) => true;
private partial Task ExecuteAddParentAsync(Role parameter) => Task.CompletedTask;
}
CommandOptionsAtribute
Parameter | Type | Description |
---|---|---|
generateCanExecute |
bool |
Controls whether the CanExecute method will be generated or not. Default is true |
asyncOptions |
AsyncRelayCommandOptions |
Options to customize the behavior of AsyncRelayCommand and AsyncRelayCommand instances. Defaults to AsyncRelayCommandOptions.None |
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- SourceCrafter.Extensions (>= 0.23.149.14)
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.24.74.428 | 132 | 3/14/2024 |
1.24.70.57 | 254 | 3/10/2024 |
0.23.302.20 | 225 | 10/29/2023 |
0.23.233.61 | 138 | 8/21/2023 |
0.23.201.96 | 189 | 7/20/2023 |
0.23.155.57 | 139 | 6/4/2023 |
0.23.155.11 | 130 | 6/4/2023 |
0.23.149.61 | 131 | 5/29/2023 |
0.23.149.53 | 124 | 5/29/2023 |
0.23.148.15 | 150 | 5/28/2023 |
0.23.122.16 | 127 | 5/2/2023 |
0.23.121.81 | 135 | 5/1/2023 |
reactivity detector rewrite from scratch