none
DataMember to support both integer and bool RRS feed

  • Question

  • Hi,

    I am facing a problem in parsing. I want allow 1/0 or true/false

    [DataMember(Name = "readonly")]
    public Int16? readonly1 { get; set; }

    But I am getting bad request response for Boolean true/false.

    How to handle above situation?

    Regards,

    Bharath

    Thursday, September 10, 2015 11:20 AM

Answers

  • Hi BharathIleni,

    In the .NET Framework, types have a concept of default values. For example, for any reference type the default value is null, and for an integer type it is zero. It is occasionally desirable to omit a data member from serialized data when it is set to its default value. Because the member has a default value, an actual value need not be serialized; this has a performance advantage.

    For more information, please refer to the following link:
    #Data Member Default Values:

    http://msdn.microsoft.com/en-us/library/aa347792(v=vs.110).aspx 

    Best Regards,

    Grady

    Monday, September 14, 2015 1:44 AM
    Moderator

All replies

  • Why you want to have 1/0? 
    Thursday, September 10, 2015 11:30 AM
  • The only thing you can do is interpret 1= true and 0 = false and intercept it  and set Boolean accordingly, or you don't use Boolean and just look at the property of 1= true and 0 = false and take a decisional path based on 1 or 0.
    Thursday, September 10, 2015 4:39 PM
  • Hi BharathIleni,

    In the .NET Framework, types have a concept of default values. For example, for any reference type the default value is null, and for an integer type it is zero. It is occasionally desirable to omit a data member from serialized data when it is set to its default value. Because the member has a default value, an actual value need not be serialized; this has a performance advantage.

    For more information, please refer to the following link:
    #Data Member Default Values:

    http://msdn.microsoft.com/en-us/library/aa347792(v=vs.110).aspx 

    Best Regards,

    Grady

    Monday, September 14, 2015 1:44 AM
    Moderator