A class [Serializable] Currency
has two fields and XmlElement
reflection attributes:
[XmlElement("currencyname")]
CurrencyValue m_Value { get; }
[XmlElement("exchangerate")]
public decimal exchangeRate { get; set; }
CurrencyValue
is an enum that is outside the Currency
class.
I've tried to use [XmlEnum("...")]
attributes and have also attempted to "pull" the set enum value inside of the class, using
[XmlElement("Value")]
public CurrencyValue m_value
{
get { return m_value.ToString(); }
}
but to no avail.
The class method ToXML()
looks like this:
public string ToXML(bool indent = false, bool omitXmlDeclaration = true, bool includeDefaultNamespaces = false)
{
XmlSerializer serializer = new XmlSerializer(typeof(Currency));
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
if (!includeDefaultNamespaces)
{
ns.Add("", "");
}
XmlWriterSettings settings = new XmlWriterSettings();
settings.Encoding = new UnicodeEncoding(false, false);
settings.Indent = indent;
settings.OmitXmlDeclaration = omitXmlDeclaration;
using (StringWriter stringWriter = new StringWriter())
{
using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, settings))
{
serializer.Serialize(xmlWriter, this, ns);
return stringWriter.ToString();
}
}
}
My question is: can an enum like that be included in the serialization of my object? I wouldn't see a reason to not include it inside the class itself, but it's possible that this enum is used elsewhere and changing it's location in my favor is not an option.