jdselig / ClayUnity

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ClayUnity

ClayUnity is a wrapper for Clay, the 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 and foremost, don't forget the namespace:

using ClaySharp;

To use Clay, 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

Credit

  • All I did was the wrapper Unity Package; full credit goes to everyone who worked on the original Clay and CastleWindsor packages. Thanks guys!
    • @loudej
    • @bleroy
    • @andrerod
    • @sebastienros
  • For Unity specific questions, you can reach me here: @jdselig

About

License:MIT License


Languages

Language:C# 100.0%