title: Basics of DataContractAttribute
body: <p>I'm looking at Microsoft's How to: <a href="http://msdn.microsoft.com/en-us/library/ms733811.aspx" rel="nofollow">Create a Basic Data Contract for a Class or Structure</a>, but it leaves me with lots of questions.</p>
  
  <p>They provide this very simplistic example:</p>
  
  <pre><code>using System;
  using System.Runtime.Serialization;
  
  [DataContract]
  public class Person
  {
    // This member is serialized.
    [DataMember]
    internal string FullName;
  
    // This is serialized even though it is private.
    [DataMember]
    private int Age;
  
    // This is not serialized because the DataMemberAttribute 
    // has not been applied.
    private string MailingAddress;
  
    // This is not serialized, but the property is.
    private string telephoneNumberValue;
  
    [DataMember]
    public string TelephoneNumber
    {
      get { return telephoneNumberValue; }
      set { telephoneNumberValue = value; }
    }
  }
  </code></pre>
  
  <p>For my case, I need this to also include another custom class object called <code>ADUser</code> (Active Directory User).</p>
  
  <p>I understand that <code>ADUser</code> has to be marked with the <code>DataContractAttribute</code>, but I do not understand how exactly to go about that.</p>
  
  <p>Here is Microsoft's class again, but this time with the <code>ADUser</code> field added:</p>
  
  <pre><code>using System;
  using System.Runtime.Serialization;
  
  [DataContract]
  public class Person
  {
    // This member is serialized.
    [DataMember]
    internal string FullName;
  
    // This is serialized even though it is private.
    [DataMember]
    private int Age;
  
    // This is not serialized because the DataMemberAttribute 
    // has not been applied.
    private string MailingAddress;
  
    // This is not serialized, but the property is.
    private string telephoneNumberValue;
  
    [DataMember]
    public string TelephoneNumber
    {
      get { return telephoneNumberValue; }
      set { telephoneNumberValue = value; }
    }
  
    [DataMember]
    public ADUser UserInfo { get; set; }
  
  }
  </code></pre>
  
  <p>I don't really understand how or what all needs to be done to my <code>ADUser</code> class, but I feel certain that <code>private</code> stuff can be left untouched.</p>
  
  <p>How would I need to <strong>fix</strong> this <code>ADUser</code> class example?</p>
  
  <pre><code>public class ADUser
  {
  
    private string first, last, loginID;
  
    public ADUser() {
      first = null;
      last = null;
      loginID = null;
    }
  
    private void getInfo() {
      // code goes here
      // which sets loginID;
    }
  
    public void SetName(string first, string last) {
      this.first = first;
      this.last = last;
      getInfo();
    }
  
    public string LoginID { get { return loginID; } }
  
  }
  </code></pre>