Giter Site home page Giter Site logo

Comments (3)

thomasclaudiushuber avatar thomasclaudiushuber commented on June 7, 2024 1

Hi @Daimonion1980 , thank you for this proposal. Makes fully sense. I will look into this and definitely provide a solution for this, so that you can test this scenario very well. I might split this request up into two parts:

  1. Allow to specify the return value of the factory's Create method
  2. Support generation of a ViewModel interface (I actually like your [ViewModelGenerateInterface] suggestion)

Timeframe will be more like end of March. Hope this works for you.

from mvvmgen.

Daimonion1980 avatar Daimonion1980 commented on June 7, 2024

Awesome. Thank you for your efforts.

Two parts was the intended way i was thinking about this problem.

from mvvmgen.

thomasclaudiushuber avatar thomasclaudiushuber commented on June 7, 2024

Feature implemented and merged into main branch. Will be part of the next MvvmGen release (Will come out soon, end of March 2023). When the new ViewModelGenerateInterface attribute is set, an interface will be generated and the generate ViewModel implements it. If the ViewModelGenerateFactory attribute is set as well, the interface will automatically be used in the factory as a return type.

The simple ViewModel below shows this:

[ViewModelGenerateInterface]
[ViewModelGenerateFactory]
[ViewModel]
public partial class EmployeeViewModel
{
}

By setting the new attribute like above, an interface will be generated and it will be automatically used for the factory. Generated code for the class above is this:

partial class EmployeeViewModel : global::MvvmGen.ViewModels.ViewModelBase, IEmployeeViewModel
{
    public EmployeeViewModel()
    {
        this.OnInitialize();
    }
    partial void OnInitialize();
}

public interface IEmployeeViewModel
{
}

public interface IEmployeeViewModelFactory : IViewModelFactory<IEmployeeViewModel> {{ }}

public class EmployeeViewModelFactory : IEmployeeViewModelFactory
{
    public EmployeeViewModelFactory()
    {
    }

    public IEmployeeViewModel Create() => new EmployeeViewModel();
}

The ViewModelGenerateFactory attribute has now also a new ReturnType property so support even more flexibility:

image

Thank you @Daimonion1980

from mvvmgen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.