Skip to content
/ clay Public
forked from 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.

License

Notifications You must be signed in to change notification settings

AmmRage/clay

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 92.5%
  • HTML 5.1%
  • Batchfile 2.4%