Clay is a dynamic C# type that will enable you to sculpt objects of any shape just as easily as in JavaScript or other dynamic languages.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
src
.hgignore
LICENSE.txt
README.md

README.md

Clay

Clay is a dynamic C# type that will enable you to sculpt objects of any shape just as easily as in JavaScript or other dynamic languages.

Usage

First, you need to instantiate a Clay factory:

dynamic New = new ClayFactory();

Then you can create objects using a number of different syntaxes:

var person = New.Person();
person.FirstName = "Louis";
person.LastName = "Dejardin";
var person = New.Person();
person["FirstName"] = "Louis";
person["LastName"] = "Dejardin";
var person = New.Person()
    .FirstName("Louis")
    .LastName("Dejardin");
var person = New.Person(new {
    FirstName = "Louis",
    LastName = "Dejardin"
});
var person = New.Person(
    FirstName: "Louis",
    LastName: "Dejardin"
);

It is then possible to access members in three different, and equivalent ways:

person.FirstName
person["FirstName"]
person.FirstName()

One of the most powerful features of Clay is its dynamic casting ability, which enables you to cast a dynamic object to a known interface, without ever having to specify the interface on the object itself:

public interface IPerson {
    string FirstName { get; set; }
    string LastName { get; set; }
}

//...

IPerson typedPerson = person;
// Look! IntelliSense! Compile-time checks!
var fullName = $"{typedPerson.FirstName} {typedPerson.LastName}";

Blog posts about Clay