constructors in a class data contract?

Just curious, if I create a data contract with a class will the constuctors get called in the client, service or both If I have the following, will the constructor get called on the client side or will the constructor get called on the service side during deserialization or not at all I have done testing and it seems to not get called, but I wanted to ask the question anyway. Thanks!

[DataContract]
public class Person
{
public Person()
{
this.Name = "No Name";
}
private string _Name;
[DataMember]
public string Name
{
get { return _Name; }
set { _Name = value; }
}
}


Answer this question

constructors in a class data contract?

  • Russ05

    No contructors are called during deserialization. But Indigo has a way of dealing with that.

    You can use the serialization callbacks to do your DC initialization.

    Please see this for further info:

    http://msdn2.microsoft.com/en-US/library/ms229752.aspx

    Thanks!

    Scott



  • constructors in a class data contract?