Skip to content
James Craig edited this page Apr 29, 2014 · 1 revision

The dynamic system within CUL is still a work in progress but is already rather powerful. The dynamic system in CUL is based around one class, Dynamo. It's similar to the ExpandoObject class that is built into the .Net framework but does away with most of the frustration that you run into.

Similar to other items like Oak, it adds a lot of functionality. They both provide a truly dynamic type to .Net and is a perfect replacement for ViewModels. It has built in change tracking, contains events to add functionality, etc. However unlike Oak, it's not focused on adding prototyping to .Net. Instead it's really only focused on adding a truly dynamic type. For instance, you can do the following:

dynamic ExampleObject=new Dynamo(new { A=1, B=2 });

The above would create a Dynamo object that had properties A that had a value of 1 and B that had a value of 2. You can also do more advance things, such as:

dynamic ExampleObject=new Dynamo(new MyClass(){ A=1, B=2}).SubSet("A");

This would create a Dynamo class that only contained the A property from the original object. Similarly you can convert the Dynamo class to pretty much any class type:

dynamic ExampleObject=new Dynamo(new { A=1, B=2 });
MyClass MyClassExample=ExampleObject;

This would convert the Dynamo object to the MyClass type and copy over any properties that matched. Properties that either do not match or aren't available on the MyClass object would be ignored. You can also tie into the data mapping system and specify how the Dynamo class should map to specific classes. So if you don't like the default way that it acts, you can override it.

As I said before, the class is still being worked on. So I plan on adding a lot of features (such as validation, etc). But even in its current state, it's helped make my coding life a lot easier.

Clone this wiki locally