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.:

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

  [Field]
  public string PublicField { get; set;}

  [Field]
  internal string InternalField { get; set; }

  [Field]
  private string PrivateField { get; set; }
}

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

[Field]
public string ReadOnlyField { get; private set; }
CodeProject

2 comments:

  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

    ReplyDelete
  2. Yes, I totally agree!

    Thanks to Gael Fraiteur and his awesome PostSharp tool.

    ReplyDelete