GithubHelp home page GithubHelp logo

stephencleary / connectedproperties Goto Github PK

View Code? Open in Web Editor NEW
42.0 8.0 7.0 146 KB

Dynamically attach properties to (almost) any object instance.

License: MIT License

C# 100.00%
c-sharp dynamic properties ephemeron

connectedproperties's Introduction

Logo

ConnectedProperties Build status codecov NuGet version API docs

Dynamically attach properties to (almost) any object instance.

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;

class Program
{
  // Display the Name of any object passed into this method.
  public static void DisplayName(object obj)
  {
    // Look up a connected property called "Name".
    var name = ConnectedProperty.Get(obj, "Name");
    Console.WriteLine("Name: " + name);
  }

  static void Main()
  {
    // Create an object to name.
    var obj = new object();

    // I dub this object "Bob".
    ConnectedProperty.Set(obj, "Name", "Bob");

    // Pass the object to the DisplayName method, which is able to retrieve the connected property.
    DisplayName(obj);
  }
}

Note that the lifetime of the connected property is exactly as if it was a real property of the object, and the lifetime of the object is not changed in any way (even if the property refers to the object). Connected properties are a true ephemeron implementation for .NET.

See the documentation for all kinds of fun details.

connectedproperties's People

Contributors

stephencleary avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.