I would like to avoid writing the same line of code in all my derived classes. I have the following structure:
using Newtonsoft.Json;
public class BaseClass
{
public string BaseProperty { get; set; }
public string Serialize() { return JsonConvert.SerializeObject(this); }
}
public class DerivedClass : BaseClass
{
public string DerivedProperty { get; set; }
}
What happens when Serialize()
is called from DerivedClass
? Is this
smart enough to know that the child object contains an extra property? Or, am I limited to writing this same line of code in each child of BaseClass
?