This project has moved. For the latest updates, please go here.
The syntax for directly using connected properties is a bit awkward. One way to make it less awkward for end-users is to wrap a connector in extension methods, as such:

// Represents a piece of data that has been read out of a file. We want to connect a property containing the source line number.
public class Token { .. }

// Allow access to the connected property via extension methods.
using Nito.ConnectedProperties;
public static class TokenExtensions
{
  private const string SourceLineNumber = Guid.NewGuid().ToString("N");

  public static int GetSourceLineNumber(Token token)
  {
    return PropertyConnector.Default.Get(token, SourceLineNumber).Get();
  }

  public static void SetSourceLineNumber(Token token, int lineNumber)
  {
    PropertyConnector.Default.Get(token, SourceLineNumber).Set(lineNumber);
  }
}

The end-user then has GetSourceLineNumber and SetSourceLineNumber extension methods that they may use, instead of having to use the Connected Properties library directly.

Last edited Aug 30, 2013 at 3:45 AM by StephenCleary, version 6

Comments

No comments yet.