Answer the question
In order to leave comments, you need to log in
How to correctly convert an inherited object to Json in asp net mvc?
Let's say we have a base class
public class ProductDto
{
public int Id { get; set; }
public string Name { get; set; }
public virtual List<PriceDto> Prices { get; set; }
}
public class ProductVm:ProductDto
{
public new List<PriceVm> Prices { get; set; }
}
Answer the question
In order to leave comments, you need to log in
The code itself looks quite crutch.
Using new to override method properties is worth it if it is __really__ very necessary and there is no other way to do it.
As far as I understand, PriceVm inherits from PriceDto
Then, for example, you can do this:
public abstract class ProductDtoBase<T> where T : PriceDto
{
public int Id { get; set; }
public string Name { get; set; }
public virtual List<T> Prices { get; set; }
}
public class ProductDto : ProductDtoBase<PriceDto>
{
}
public class ProductVm : ProductDtoBase<PriceVm>
{
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question