Basically i have a settings class like this:
class Settings
{
Color BackgroundColor {get;set;}
Color ForegroundColor {get;set;}
Color GridColor {get;set;}
Color HighlightColor {get;set;}
//... etc
}
And i want to be able to do both - serialize the settings class and edit the colors in propertygrid.
The solution I've come up so far is this:
class Settings
{
[XmlIgnore]
Color BackgroundColor {get;set;}
[Browsable(false)]
[XmlElement("BackgroundColor")]
public string HtmlBackgroundColor
{
get
{
return ColorTranslator.ToHtml(BackgroundColor);
}
set
{
Color = ColorTranslator.FromHtml(value);
}
}
// etc
}
But this approach sucks because I've to write a lot of code for each color.
The preferred solution should look something like this:
class Settings
{
SColor BackgroundColor {get;set;}
SColor ForegroundColor {get;set;}
SColor GridColor {get;set;}
SColor HighlightColor {get;set;}
// etc
}
Where SColor is editable in propertygrid exactly like the System.Drawing.Color, but at the same time is serializable.
How could I achieve this?