title: WCF: Exposing readonly DataMember properties without set?
body: <p>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 to add a [DataMember] property without having both get and set. </p>
  
  <p>So - is there a way to have a [DataMember] property without setter? </p>
  
  <pre><code>[DataContract]
  class SomeClass
  {
      private readonly int _id; 
  
      public SomeClass() { .. }
  
      [DataMember]
      public int Id { get { return _id; } }        
  
      [DataMember]
      public string SomeString { get; set; }
  }
  </code></pre>
  
  <p>Or will the solution be use the [DataMember] as the field - (like e.g. shown <a href="https://stackoverflow.com/questions/556775/wcf-datamember-attribute-on-property-vs-member/556886#556886">here</a>)? Tried doing this too, but it doesn't seem to care the field is readonly..? </p>
  
  <p><em>Edit</em>: Is the only way to make a readonly property by hacking it like this? (no - I don't want to do this...) </p>
  
  <pre><code>[DataMember]
  public int Id
  {
      get { return _id; }
      private set { /* NOOP */ }
  }
  </code></pre>