c# - ViewModel Inheritance -


i want load screen viewmodel depending on option selected.

i thought inheritance key here, lot of properties same. below extract of code have.

public partial class form1 : form {     public form1()     {         initializecomponent();          bool ishandheld = false;          var pdv1 = ishandheld == true ? new pdvhh() : new pdv();          txtcaseid.text = pdv1.caseid;         txtpdv.text = ishandheld == true ? pdv1.pdvstring : string.empty;         txtpdvhh.text = ishandheld == true ? pdv1.pdvhhstring : string.empty;      } }  class basepdv {     public string caseid { get; set; } }  class pdv : basepdv {     public string pdvstring { get; set; } }  class pdvhh : basepdv {     public string pdvhhstring { get; set; } } 

the error receiving is... "type of conditional expression cannot determined because there no implicit conversion between 'windowsformsapplication1.pdvhh' , 'windowsformsapplication1.pdv'"

i'm hoping can give me guidance on solution this.

ok, question not inheritance or viewmodels how ?: (the conditional operator) works.

the following fix it:

var pdv1 = ishandheld == true ? (basepdv) new pdvhh() : (basepdv) new pdv(); 

while code looks plausible, docs need conversion between pdvhh , pdv, either direction, conversion basepdv isn't considered.

when can find common name pdvstring , pdvhhstring , implement single property in base class, might work want. , simpler. note class pdv : basepdv {} ok.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -