Questions tagged [datamember]
204 questions
623
votes
18 answers
Does the 'mutable' keyword have any purpose other than allowing a data member to be modified by a const member function?
A while ago, I came across some code that marked a data member of a class with the mutable keyword. As far as I can see it simply allows you to modify a member in a const-qualified member method:
class Foo
{
private:
mutable bool done_; …

Rob
- 76,700
- 56
- 158
- 197
202
votes
8 answers
When to use DataContract and DataMember attributes?
I am very confused about the DataContract attribute in WCF. As per my knowledge it is used for serializating user defined type like classes. I wrote one class which is exposed at client side like this.
[DataContract]
public class Contact
{
…

sam
- 2,029
- 2
- 13
- 3
63
votes
5 answers
WCF: Exposing readonly DataMember properties without set?
I have a server side class which I make available on the client side through a [DataContract]. This class has a readonly field which I'd like to make available through a property. However, I'm unable to do so because it doesn't seem that I'm allowed…

stiank81
- 25,418
- 43
- 131
- 202
45
votes
6 answers
Configure JSON.NET to ignore DataContract/DataMember attributes
We are running into a situation on an MVC3 project with both the Microsoft JSON serializers and JSON.NET.
Everybody knows DateTime's are basically broken in Microsoft's serializers, so we switched to JSON.NET to avoid this issue. That works great,…

Nick
- 9,113
- 4
- 25
- 29
35
votes
5 answers
What can a 'const' method change?
C++ methods allow a const qualifier to indicate that the object is not changed by the method. But what does that mean? Eg. if the instance variables are pointers, does it mean that the pointers are not changed, or also that the memory to which they…

Daniel
- 924
- 1
- 11
- 16
32
votes
1 answer
Why is using [DataMember(EmitDefaultValue = false)] not recommended?
In WCF you can define a contract using the [DataContract] and [DataMember] attributes, like this:
[DataContract]
public class Sample
{
[DataMember(EmitDefaultValue = false, IsRequired = false)]
public string Test { get; set; }
}
This…

oɔɯǝɹ
- 7,219
- 7
- 58
- 69
27
votes
2 answers
DataMember's Name property is ignored with [FromUri] property in WebApi service
We are creating RestService with Asp.Net WebApi. But for some reason Name property is ignored in DataMember attribute when trying to deserialize complex property with [FromURI] attribute.
For example we might have:
Method:
public IHttpActionResult…

Igor
- 3,054
- 1
- 22
- 28
23
votes
3 answers
DataContract, default DataMember value
Is there a way to choose default values of attributes that are not in the xml file during deserialization?
If the mAge attribute is not present in the xml file, I want to use a default value of 18. Is it possible ?
[DataContract]
public class…

BuzBuza
- 607
- 2
- 7
- 19
15
votes
2 answers
Is the DataMember IsRequired attribute in combination with a Nullable type contradictory?
I came across this today in a WCF contract:
[DataMember(IsRequired = true)]
public DateTime? LastModified { get; set; }
What are the consequences of IsRequired = True and a nullable DateTime? They appear to be contradictory to each other.

Rebecca
- 13,914
- 10
- 95
- 136
15
votes
3 answers
Sending a Tuple object over WCF?
Is the System.Tuple class supported by WCF's Data Contract Serializer (i.e., can I pass Tuple objects to WCF calls and/or receive them as part or all of the result)?
I found this page, but not the clear, definitive "you can send and receive Tuples…

Donut
- 110,061
- 20
- 134
- 146
12
votes
2 answers
Serialization DataMember (name) override issue
I am using a DataContractJsonSerializer and have an issue with the DataMember Name.
I made a base class and several derived classes. I need the derived classes because I have different json strings. I want to deserialize the json strings and…

royu
- 377
- 2
- 5
- 15
12
votes
1 answer
Adding a DataMember to an existing DataContract in WCF
I would like to add a DataMember to one of my DataContracts. I would like to know how existing servers and clients will behave in the presence of a new DataMember if one of the parties isn't updated.
I recall there is a way to make the DataMember…

Jader Dias
- 88,211
- 155
- 421
- 625
9
votes
2 answers
WCF: is there an attribute to make parameters in the OperationContract required?
I use [DataMember(IsRequired=true)] to make the DataContract properties required. There doesn't seem to be some IsRequired for the OperationContract parameters. How do I make them required and not allow null?
The parameter in of OperationContract…

Dieko
- 101
- 1
- 5
8
votes
1 answer
WCF - Decorating IEnumerable with DataMember causes Exception:The underlying connection was closed: The connection was closed unexpectedly
I have created a WCF service which returns IEnumerable.
The CyberResourceProvisioningAction type has a property of AccountInformation IEnumerable. When I decorate the…

ahsteele
- 26,243
- 28
- 134
- 248
8
votes
3 answers
What does it mean to put DataMemberAttribute on interface member?
What does it mean to put a DataMemberAttribute on an interface member?
How does this affect derived classes?

Adibe7
- 3,469
- 7
- 30
- 36