{"id":19340063,"url":"https://github.com/damienaicheh/mvvmcodegenerator","last_synced_at":"2025-04-23T02:31:11.842Z","repository":{"id":105804841,"uuid":"197444892","full_name":"damienaicheh/MvvmCodeGenerator","owner":"damienaicheh","description":"Mvvm generator C#","archived":false,"fork":false,"pushed_at":"2019-09-15T19:39:12.000Z","size":589,"stargazers_count":26,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-02T06:51:10.749Z","etag":null,"topics":["csharp","generator","mvvm"],"latest_commit_sha":null,"homepage":"https://damienaicheh.github.io/nuget/xamarin/xamarin.forms/dotnet/2019/07/31/a-complete-overview-of-mvvmcodegenerator-en.html","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/damienaicheh.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-17T18:47:57.000Z","updated_at":"2024-12-22T13:47:52.000Z","dependencies_parsed_at":"2023-04-04T08:17:47.904Z","dependency_job_id":null,"html_url":"https://github.com/damienaicheh/MvvmCodeGenerator","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damienaicheh%2FMvvmCodeGenerator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damienaicheh%2FMvvmCodeGenerator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damienaicheh%2FMvvmCodeGenerator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damienaicheh%2FMvvmCodeGenerator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/damienaicheh","download_url":"https://codeload.github.com/damienaicheh/MvvmCodeGenerator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250357607,"owners_count":21417312,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","generator","mvvm"],"created_at":"2024-11-10T03:24:48.763Z","updated_at":"2025-04-23T02:31:11.833Z","avatar_url":"https://github.com/damienaicheh.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Schema](./Documentation/logo.png)\n\nMVVM code generator tool for .NET.\n\n## Install\n\nAvailable on [NuGet](https://www.nuget.org/packages/MvvmCodeGenerator).\n\n## Why ?\n\nI decided to create this tool to avoid having to always write boilerplate code for my ViewModels. This NuGet is built on top of the [Rosyln .NET compiler](https://github.com/dotnet/roslyn).\n\nThe advantages of using it are :\n*   Reduce the amount of code in your ViewModels\n*   The ViewModels only contains the more important code\n*   Migrate from one MVVM Framework to another easily\n\n## Features\n\nThis NuGet allows you to generate your ViewModels with the Properties and Commands specified in your XML file. The code generated will depend on the Mvvm Frameworks you like.\n\nThis tool now support these MVVM Frameworks:\n\n* [MvvmLightLibs](https://www.nuget.org/packages/MvvmLightLibs/)\n* [MvvmCross](https://www.nuget.org/packages/MvvmCross/)\n* [Mvvmicro](https://www.nuget.org/packages/Mvvmicro/)\n* [FreshMvvm](https://www.nuget.org/packages/FreshMvvm/)\n* [Prism.Core](https://www.nuget.org/packages/Prism.Core/)\n\n## Tutorial\n\nYou will find a complete tutorial here:\n##### English version :\n[https://damienaicheh.github.io/nuget/xamarin/xamarin.forms/dotnet/2019/07/31/a-complete-overview-of-mvvmcodegenerator-en](https://damienaicheh.github.io/nuget/xamarin/xamarin.forms/dotnet/2019/07/31/a-complete-overview-of-mvvmcodegenerator-en)\n\n##### French version :\n[https://damienaicheh.github.io/nuget/xamarin/xamarin.forms/dotnet/2019/07/31/a-complete-overview-of-mvvmcodegenerator-fr](https://damienaicheh.github.io/nuget/xamarin/xamarin.forms/dotnet/2019/07/31/a-complete-overview-of-mvvmcodegenerator-fr)\n\n## Usage\n### Setup\n\nFirst of all, install the [NuGet](https://www.nuget.org/packages/MvvmCodeGenerator) package to your .NetStandard project for example.\nThen create a new file called `MvvmCodeGenMapper.xml` at the root of your library project. This file will contain the definition of your ViewModels.\n\n### Configure your generator\n\nNow it's time to define which generator we want to use, 4 options are available:\n* mvvmlightlibs\n* mvvmcross\n* mvvmicro\n* freshmvvm\n* prismcore\n\nChoose the one you like and declare it inside your `MvvmCodeGenMapper.xml` like this:\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\" ?\u003e\n\u003cResources\u003e\n    \u003cGenerator Value=\"mvvmlightlibs\" /\u003e\n\u003c/Resources\u003e    \n```\n\n### Create your ViewModels\n\nLet's define the ViewModels inside the `ViewModels` tags. You can define as many `ViewModels` tags as needed. Here is an example:\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\" ?\u003e\n\u003cResources\u003e\n    \u003cGenerator Value=\"mvvmlightlibs\" /\u003e\n    \u003cViewModels Namespace=\"MvvmCodeGenerator.Sample\" DestinationFolder=\"ViewModel\"\u003e\n        \u003cViewModel Key=\"Root\"\u003e\n              \u003cProperty Name=\"IsLoading\" Type=\"bool\" Description=\"Gets or sets the loader property.\" /\u003e\n        \u003c/ViewModel\u003e\n        \u003cViewModel Key=\"Dashboard\"  Base=\"Root\"\u003e\n            \u003cProperty Name=\"Title\" Type=\"string\" Description=\"Gets or sets the title.\" /\u003e\n            \u003cCommand Name=\"Buy\" Description=\"Gets or sets the command to buy a boat\" /\u003e\n            \u003cAsyncCommand Name=\"Consultation\" Parameter=\"string\" CanExecute=\"true\" Description=\"Gets or sets the command to consult my orders\" /\u003e\n        \u003c/ViewModel\u003e \n    \u003c/ViewModels\u003e   \n\u003c/Resources\u003e    \n```\n\nAs you can see above, you can specify a list of ViewModels for a specific namespace and destination folder.\n\nThis XML will generate the 2 ViewModels with their **.g.cs** class associated:\n\nThe `RootViewModel.cs`:\n```csharp\nnamespace MvvmCodeGenerator.Sample\n{\n    using System;\n    using System.Collections.Generic;\n    using System.Threading;\n    using System.Threading.Tasks;\n    using GalaSoft.MvvmLight.Command;\n\n    public partial class RootViewModel\n    {\n    }\n}\n```\n\nThe `RootViewModel.interface.g.cs`:\n```csharp\n//------------------------------------------------------------------------------ \n// \u003cauto-generated\u003e \n// This code was generated by MvvmCodeGenerator.\n// Runtime Version:4.0.30319.42000\n// \n// Changes to this file may cause incorrect behavior and will be lost if\n// the code is regenerated.\n// \u003c/auto-generated\u003e \n//------------------------------------------------------------------------------\nnamespace MvvmCodeGenerator.Sample\n{\n    using System;\n    using System.Collections.Generic;\n    using System.Threading;\n    using System.Threading.Tasks;\n    using GalaSoft.MvvmLight.Command;\n\n    public interface IRootViewModel : System.ComponentModel.INotifyPropertyChanged\n    {\n        System.Boolean IsLoading\n        {\n            get;\n        }\n    }\n}\n```\n\nThe `RootViewModel.part.g.cs`:\n```csharp\n//------------------------------------------------------------------------------ \n// \u003cauto-generated\u003e \n// This code was generated by MvvmCodeGenerator.\n// Runtime Version:4.0.30319.42000\n// \n// Changes to this file may cause incorrect behavior and will be lost if\n// the code is regenerated.\n// \u003c/auto-generated\u003e \n//------------------------------------------------------------------------------\nnamespace MvvmCodeGenerator.Sample\n{\n    using System;\n    using System.Collections.Generic;\n    using System.Threading;\n    using System.Threading.Tasks;\n    using GalaSoft.MvvmLight.Command;\n\n    public partial class RootViewModel : GalaSoft.MvvmLight.ViewModelBase, MvvmCodeGenerator.Sample.IRootViewModel\n    {\n        private System.Boolean isLoading;\n        /// \u003csummary\u003e\n        // Gets or sets the loader property.\n        /// \u003c/summary\u003e\n        public System.Boolean IsLoading\n        {\n            get =\u003e this.isLoading;\n            set =\u003e this.Set(ref this.isLoading, value);\n        }\n    }\n}\n```\n\nThe `DashboardViewModel.cs` where you will implement the Commands declared:\n\n```csharp\nFolder destination ./MvvmCodeGenerator.Dev/ViewModel\nnamespace MvvmCodeGenerator.Sample\n{\n    using System;\n    using System.Collections.Generic;\n    using System.Threading;\n    using System.Threading.Tasks;\n    using GalaSoft.MvvmLight.Command;\n\n    public partial class DashboardViewModel\n    {\n    }\n}\n```\n\nThe `DashboardViewModel.interface.g.cs`:\n```csharp\n//------------------------------------------------------------------------------ \n// \u003cauto-generated\u003e \n// This code was generated by MvvmCodeGenerator.\n// Runtime Version:4.0.30319.42000\n// \n// Changes to this file may cause incorrect behavior and will be lost if\n// the code is regenerated.\n// \u003c/auto-generated\u003e \n//------------------------------------------------------------------------------\nnamespace MvvmCodeGenerator.Sample\n{\n    using System;\n    using System.Collections.Generic;\n    using System.Threading;\n    using System.Threading.Tasks;\n    using GalaSoft.MvvmLight.Command;\n\n    public interface IDashboardViewModel : MvvmCodeGenerator.Sample.IRootViewModel\n    {\n        System.String Title\n        {\n            get;\n        }\n\n        System.Windows.Input.ICommand BuyCommand\n        {\n            get;\n        }\n\n        System.Boolean IsConsultationCommandRunning\n        {\n            get;\n        }\n\n        System.Windows.Input.ICommand ConsultationCommand\n        {\n            get;\n        }\n    }\n}\n```\n\nThe `DashboardViewModel.part.g.cs`:\n```csharp\n//------------------------------------------------------------------------------ \n// \u003cauto-generated\u003e \n// This code was generated by MvvmCodeGenerator.\n// Runtime Version:4.0.30319.42000\n// \n// Changes to this file may cause incorrect behavior and will be lost if\n// the code is regenerated.\n// \u003c/auto-generated\u003e \n//------------------------------------------------------------------------------\nnamespace MvvmCodeGenerator.Sample\n{\n    using System;\n    using System.Collections.Generic;\n    using System.Threading;\n    using System.Threading.Tasks;\n    using GalaSoft.MvvmLight.Command;\n\n    public partial class DashboardViewModel : MvvmCodeGenerator.Sample.RootViewModel, MvvmCodeGenerator.Sample.IDashboardViewModel\n    {\n        private System.String title;\n        private System.Boolean isConsultationCommandRunning;\n        private GalaSoft.MvvmLight.Command.RelayCommand buyCommand;\n        private GalaSoft.MvvmLight.Command.RelayCommand\u003cstring\u003e consultationCommand;\n        /// \u003csummary\u003e\n        // Gets or sets the title.\n        /// \u003c/summary\u003e\n        public System.String Title\n        {\n            get =\u003e this.title;\n            set =\u003e this.Set(ref this.title, value);\n        }\n\n        /// \u003csummary\u003e\n        // Gets or sets the value to know if the associated async command is running.\n        /// \u003c/summary\u003e\n        public System.Boolean IsConsultationCommandRunning\n        {\n            get =\u003e this.isConsultationCommandRunning;\n            set =\u003e this.Set(ref this.isConsultationCommandRunning, value);\n        }\n\n        /// \u003csummary\u003e\n        // Gets or sets the command to buy a boat\n        /// \u003c/summary\u003e\n        public System.Windows.Input.ICommand BuyCommand\n        {\n            get =\u003e this.buyCommand ?? (this.buyCommand = new GalaSoft.MvvmLight.Command.RelayCommand(ExecuteBuyCommand)); // You must implement the following method(s): ExecuteBuyCommand and OnExecuteBuyCommandAsyncError\n        }\n\n        /// \u003csummary\u003e\n        // Gets or sets the command to consult my orders\n        /// \u003c/summary\u003e\n        public System.Windows.Input.ICommand ConsultationCommand\n        {\n            get =\u003e this.consultationCommand ?? (this.consultationCommand = new GalaSoft.MvvmLight.Command.RelayCommand\u003cstring\u003e(async (value) =\u003e\n            {\n                try\n                {\n                    this.IsConsultationCommandRunning = true;\n                    await ExecuteConsultationCommandAsync(value);\n                }\n                catch (System.Exception ex)\n                {\n                    OnExecuteConsultationCommandAsyncError(ex);\n                }\n                finally\n                {\n                    this.IsConsultationCommandRunning = false;\n                }\n            }\n\n            , CanExecuteConsultationCommand)); // You must implement the following method(s): ExecuteConsultationCommandAsync and the CanExecuteConsultationCommand and OnExecuteConsultationCommandAsyncError\n        }\n    }\n}\n```\n\nNow you juste have to implement the commands in each *ViewModel.cs* file.\n\nA *IsRunning* property is added in the case of **MvvmLightLibs** and **FreshMvvm** async commands for you. **MvvmCross** and **Mvvmicro** already have this kind of mechanism.\n\n### Define your ViewModels and ItemViewModels\n\nEach `ViewModel` tag has different properties :\n\n* **Key** : The ViewModel name prefix\n* **Base** : The ViewModel name prefix of the parent class\n\nIf you want to generate an ItemViewModel for each items of a listview for example, just use the `ItemViewModel` tag instead of `ViewModel`. You will have the same properties than the `ViewModel` tag available.\n\nYou can specify the **Properties** and **Commands** for each ViewModels:\n\nFor the **Properties** you have the ability to define it using the `Property` tag:\n\n* **Name** : The name of the property\n* **Description** : The comment associated to the property\n* **Type** : The type of the property\n\nYou have different options to specify the **Type** of your property\n\nHere the list of base types that can be used:\n\n* **string**\n* **int**\n* **long**\n* **bool**\n* **float**\n* **object**\n* **double**\n* **DateTime**\n* **DateTimeOffset**\n* **TimeSpan**\n\nIf the type you need is not in this list, you can just specify it using the complete namespace for example:\n\n```xml\n\u003cProperty Name=\"House\" Type=\"Xamarin.Sample.Models.House\" Description=\"Gets or sets the house.\" /\u003e\n```\n\nYou can also declare a list like this:\n```xml\n\u003cProperty Name=\"names\" Type=\"list string\" Description=\"Gets or sets all names.\" /\u003e\n\u003cProperty Name=\"AllHouses\" Type=\"list Xamarin.Sample.Models.House\" Description=\"Gets or sets all houses.\" /\u003e\n```\n\nFor the **Commands** you have the ability to define:\n\n* Synchronous command using the `Command` tag\n* Asynchronous command using the `AsyncCommand` tag\n\nEach command tag has different properties:\n* **Name** : The name of the command\n* **Parameter** : The parameter type of the command\n* **CanExecute** : A boolean to know if the command must have a can execute method or not\n* **Description** : The comment associated to the command\n\n### Visual Studio display\n\nIf you build your project now, you will have this kind of result:\n![Visual Studio File Viewer](./Documentation/project_structured.png)\n\nIf your files are not grouped correctly like above, please check if the `MvvmCodeGenMapper.g.targets` file was imported correctly in your *.csproj* associated to your project. If it's not the case you can do it manually by adding this line:\n\n```xml\n\u003cImport Project=\"MvvmCodeGenMapper.g.targets\" /\u003e\n```\n\nRelaod your project and you will be good to go.\n\nYou will find a full example in the `Xamarin.Sample` project [here](https://github.com/damienaicheh/MvvmCodeGenerator/tree/master/Sources/Xamarin.Sample)\n\n\n## Contributions\n\nContributions are welcome! If you find a bug  or if you want a feature please report it.\n\nIf you want to contribute create a branch from the current master branch and when your code is ready create a pull request.\n\n### License\n\n![MIT © Damien](https://img.shields.io/badge/licence-MIT-blue.svg) \n\n© [Damien Aicheh](https://damienaicheh.github.io/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdamienaicheh%2Fmvvmcodegenerator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdamienaicheh%2Fmvvmcodegenerator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdamienaicheh%2Fmvvmcodegenerator/lists"}