bleroy / 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.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

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.

License:MIT License


Languages

Language:C# 92.5%Language:HTML 5.1%Language:Batchfile 2.4%