O
O
Oxoron2015-09-28 15:24:09
.NET
Oxoron, 2015-09-28 15:24:09

How to set up an XML serializer?

Good afternoon.
Sending an XML request to a Web server. He wants boolean true to be encoded as "Y", false as "N". As a result, the serializable class class looks like

public string MyBool
{
  get{ return _myBool;}
  set
  {
    if(value == "Y" || value == "N"){ _myBool = value;}
    else {throw new Exception();}
  }
}

Is there a way to create a boolean property public bool MyBoolthat would (de)serialize to a string according to the above rule?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Makarov, 2015-09-28
@Oxoron

stackoverflow.com/questions/84449/xml-serialize-bo...

[XmlIgnore]
public bool MyValue { get; set; }

/// <summary>Get a value purely for serialization purposes</summary>
[XmlElement("MyValue")]
public string MyValueSerialize
{
    get { return this.MyValue ? "1" : "0" }
    set { this.MyValue = XmlConvert.ToBoolean(value); }
}

although ..... practically does not differ from yours

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question