-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
generating Viewmodel from derived model #16
Comments
Hi @khaledafifi , sorry, I was on holidays. You're missing the public access modifier here. Private members are not visible in subclasses. Should be
Please let me know if this works for you. |
the same result .. the generated vm publish prosperities only from the derived class not the base. |
Hi @khaledafifi , I tried it. I defined these ViewModels
All properties from A are available on B through inheritance and this code works:
Note that the code editor in Visual Studio might show errors where no errors exist. They still need to catch up a bit with editor support for source generators. |
Ok, reproduced. You're using the ModelType property of the attribute I guess to generate a ViewModel from a Model. So, for the code below, the public class BaseType
{
public string? Name { get; set; }
}
public class SubType : BaseType
{
public string? Email { get; set; }
}
[ViewModel(ModelType = typeof(SubType))]
public partial class MyViewModel
{
} The generated output in MvvmGen version 1.1.2 is this, the // <auto-generated>
// This code was generated for you by
// ⚡ MvvmGen, a tool created by Thomas Claudius Huber (https://www.thomasclaudiushuber.com)
// Generator version: 1.1.2
// </auto-generated>
using MvvmGen.Commands;
using MvvmGen.Events;
using MvvmGen.ViewModels;
namespace WpfApp2
{
partial class MyViewModel : global::MvvmGen.ViewModels.ViewModelBase
{
public MyViewModel()
{
this.OnInitialize();
}
partial void OnInitialize();
public string? Email
{
get => Model.Email;
set
{
if (Model.Email != value)
{
Model.Email = value;
OnPropertyChanged("Email");
}
}
}
protected WpfApp2.SubType Model { get; set; }
}
} |
Thank you @khaledafifi for the issue. It's fixed and it will be part of an upcoming release. |
class A
{
string id{get; set;}
string Name{get; set;}
}
class B : A
{
string Email {get; set; }
}
the generated ViewModel from B must include props from A but it doesn't.
The text was updated successfully, but these errors were encountered: