Include enum in serialization when defined outside of class

Anydayhagefag

New Member
A class \[code\][Serializable] Currency\[/code\] has two fields and \[code\]XmlElement\[/code\] reflection attributes:\[code\][XmlElement("currencyname")]CurrencyValue m_Value { get; }[XmlElement("exchangerate")]public decimal exchangeRate { get; set; }\[/code\]\[code\]CurrencyValue\[/code\] is an enum that is outside the \[code\]Currency\[/code\] class.I've tried to use \[code\][XmlEnum("...")]\[/code\] attributes and have also attempted to "pull" the set enum value inside of the class, using\[code\][XmlElement("Value")]public CurrencyValue m_value{ get { return m_value.ToString(); }}\[/code\]but to no avail.The class method \[code\]ToXML()\[/code\] looks like this:\[code\]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(); } }}\[/code\]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.
 
Back
Top