Project Description
The Nito Connected Properties library provides a simple API to attach properties to most .NET objects at runtime. It is developed in C# with code contracts.
The 2-Minute Intro: Connecting a "Name" to (almost) any Object
The following code shows how to connect a "Name" property to an object:
// Use the Connected Properties library.
using Nito.ConnectedProperties;
using Nito.ConnectedProperties.Implicit;
class Program
{
// Define the "tag" for the "Name" connected property.
public struct NameProperty {};
// Display the Name of any object passed into this method.
public static void DisplayName(object obj)
{
// Look up the property, of type "string", with tag "NameProperty".
var nameProperty = obj.GetConnectedProperty<string, NameProperty>();
Console.WriteLine("Name: " + nameProperty.Get());
}
static void Main()
{
// Create an object to name.
var obj = new object();
// I dub this object "Bob".
var nameProperty = obj.GetConnectedProperty<string, NameProperty>();
nameProperty.Set("Bob");
// Pass the object to the DisplayName method, which is able to retrieve the connected property.
DisplayName(obj);
}
}
See the
documentation tab for all kinds of fun details.
Getting Started
Most users should simply add a reference to the Net40\Release\ConnectedProperties.dll or SL4\Release\ConnectedProperties.dll, as appropriate. IntelliSense is automatically applied.
If you install Connected Properties via NuGet, then this is done automatically for you.Note: The Net40 binaries should work with any .NET 4.0 Client or Full Profile projects. This includes class libraries, ASP.NET, WPF, etc. The SL4 binaries should work with Silverlight 4.0 projects. Earlier versions of Silverlight, and Silverlight for Windows Phone / XNA are not supported.
If you install Connected Properties via NuGet, then the correct binaries are used automatically.The Release build does perform precondition checks, to ensure the library is being used correctly. If you need minimum overhead, you can use the "Release (no precondition checks)" build.
This is not an option if you install Connected Properties via NuGet. You must download the CodePlex zip file to get the "Release (no precondition checks)" build.If you suspect a bug in the Connected Properties library itself, you may reference the Net40\Debug\ConnectedProperties.dll or SL4\Debug\ConnectedProperties.dll instead of the Release versions. This will add many more checks at runtime, such as internal consistency checks.
This is not an option if you install Connected Properties via NuGet. You must download the CodePlex zip file to get the Debug build.