Monday, September 14, 2009

Persistent fields accessibility levels

Havasvölgyi Ottó pointed out that DataObjects.Net 4 manual contains code samples with public persistent fields only. I’m going to remedy this deficiency. DataObjects.Net 4 supports all kind of persistent fields: private, internal and public, e.g.:

public class MyEntity : Entity
  [Field, Key]
  public int Id { get; private set; }

  public string PublicField { get; set;}

  internal string InternalField { get; set; }

  private string PrivateField { get; set; }

Moreover, you can combine accessibility modifiers as you like, e.g.:

public string ReadOnlyField { get; private set; }


  1. Much more convenient than what we had to do in DO3.9 (didn't support different access mods when declared abstract)... you had to declare it virtual and use GetProperty/SetProperty

  2. Yes, I totally agree!

    Thanks to Gael Fraiteur and his awesome PostSharp tool.