In my WPF Application I am using a custom Control that looks like this:
public class FancyLabel : Label
{
public string FancyProperty { get; set; }
public FancyLabel()
{
Height = 26;
BorderBrush = Brushes.Gray;
Background = Brushes.LightGray;
}
}
The Control has customizable attributes like 'FancyAttr' an can be changed during runtime. On application exit I am trying to save the control / changes in a JSON File like this:
string output = JsonConvert.SerializeObject(new FancyLabel(),
Formatting.Indented,
new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
});
File.WriteAllText("C:/test/savefile.txt", output);
The problem is, that always all Properties from the inherited Label class get serialized and saved aswell which causes the save process to be unbareably long and the save file to be huge. Is there a way to define that only some properties or properties form the class 'FancyLabel' get serialized and saved?