I have the following:
[DataContract]
public class Foo
{
[DataMember(EmitDefaultValue = true)
public bool Bar { get; set; }
}
2 Questions:
What really happens here because my bool can't really be null, so if I emit the default value then what?
How do I make it so that if someone passes a message without the Bar part then it my server sets it to true instead of false by default?
Basically, my bar member is not required to be transmitted over the soap message and if it isn't I want it to default to true, not false. I'm not sure of the proper combination to make my message sizes efficient (cut out anything unnecessary) and then default the value to what I want if it isn't in the message?
EmitDefaultValue
is true by default.You can try to useDefaultValue
attribute fromSystem.ComponentModel
but I'm not sure if it works.I just tested
DefaultValue
attribute and it doesn't work. It means that you cannot change default value - default value of the data type will be always used.If you want to set your
Bar
totrue
use: