I have the following class:
public class DisplayFunction
{
[System.Xml.Serialization.XmlAttribute()]
public byte[] Color
{
get;
set;
}
[System.Xml.Serialization.XmlAttribute()]
public FunctionShape Shape
{
get;
set;
}
[System.Xml.Serialization.XmlAttribute()]
public int Id
{
get;
set;
}
}
I am using xml serializer and getting the result:
<DisplayFunctions Color="et57hQ==" Shape="Bar" Id="514" />
while i want the result to be:
<DisplayFunctions Color="122,222,123,133" Shape="Bar" Id="514" />
How can I get that result ?
The XML serializer is serializing the Color using byte array. So the result is odd.
My suggesting is using a public property of type
stringto serialize the color, and then use a conversion to convert colors to strings and vice versa.So, you need the following:
Note: If you need to convert the
Colorto abyte[]you can add an additional property to get the color as abyte[]also ignoring with[XmlIgnore]attribute.If the format provided by the
ColorTranslator.ToHtmlis not valid for you, you can use a custom Color translation, for exampleAnd a similar method for for parsign a color from string.
Hope it helps-