How can I get XmlSerializer to encode bools as yes/no?

后端 未结 7 2155
情话喂你
情话喂你 2020-12-31 05:49

I\'m sending xml to another program, which expects boolean flags as \"yes\" or \"no\", rather than \"true\" or \"false\".

I have a class defined like:



        
7条回答
  •  天命终不由人
    2020-12-31 06:09

    I use the property method, but instead of checking to see if the string is equal to yes or no, I prefer to check if the string starts with (case insensitive) "YT1". This allows the file to contain true, True, t, T, y, Y, yes, Yes, 1, etc. all which will evaluate to true. While I can specify that false is false, False, f, F, n, N, no, No, 0, etc., anything that doesn't match the true still evaluates to false.

提交回复
热议问题