Say we have a struct that it\'s data is provided by un-managed byte array using Marshal.PtrToStructure.
The C# struct layout:
[StructLayout(LayoutKin
This is how I did it:
public class MySerializableClass
{
private string dummy;
[XmlElement("NaughtyXmlCharacters")]
public string NaughtyXmlCharactersAsString
{
get
{
return BitConverter.ToString(NaughtyXmlCharacters);
}
set
{
// without this, the property is not serialized.
dummy = value;
}
}
[XmlIgnore]
public byte[] NaughtyXmlCharacters
{
get;
set;
}
}
The bytes are then formatted as hexadecimal values and separated with a minus sign: 00-AF-B1