XML Serialization private field problem
-
Hi, I know that the XML Serializer does not support serializing private field. So I use a public field to get/set the private field like this:
namespace TestObjectToXML.CarComponent { [XmlRootAttribute("Wheel", Namespace="", IsNullable=false)] public class Wheel : IWheel { public string wheelSize; private string _wheelType; public Wheel() { } public string wheelType { get{return this._wheelType;} set{this._wheelType = value;} } public string GetWheelType() { return this._wheelType; } public void SetWheelType(string type) { this._wheelType = type; } } }
However, if the wheel class needs to implement methods from a IWheel interface which has already some get and set method for the wheelType, is there any way to simplify this? Sometimes the interface cannot be modified and has a lot of such get and set methods.namespace TestObjectToXML.CarComponent { /// /// Summary description for IWheel. /// public interface IWheel { string GetWheelType(); void SetWheelType(string type); } }
Thanks