Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. XML Serialization private field problem

XML Serialization private field problem

Scheduled Pinned Locked Moved XML / XSL
xmljsonhelpquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    scchan1984
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups