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

Many of the more powerful portions of CUL are built upon the the data mapping system. For those of you that have experience with such systems, the built in system is a very simplified version of Automapper but with some differences. For one thing, the system is built to be flexible enough to copy data between functions and properties and vice versa without much difficulty. At the same time, it doesn't have nearly the configuration options that Automapper does. That said, if you want to write a wrapper for Automapper or some other system, you can tie it into CUL without too much difficulty.

Anyway, in order to use the system, you would just do the following:

typeof(MyClass).MapTo(typeof(MyClass2))
               .AddMapping(x=>x.Property1,x=>x.Property1)
               .AddMapping(x=>x.Property2,x=>x.Property2);

The above code sets up a mapping between MyClass and MyClass2 and matches up Property1 and Property2 for each class. You could also just tell the system to automatically map the properties:

typeof(MyClass).MapTo(typeof(MyClass2))
               .AutoMap();

Once this is done, you can simply call the To extension and it will automatically use this mapping:

MyClass ExampleResult=new MyClass2().To();

Assuming that there is no direct conversion, it will then use the mapping that you specified. You can also directly use the mapping, if you need to:

typeof(MyClass).MapTo(typeof(MyClass2))
               .Copy(new MyClass(),new MyClass2());

The example above isn't that useful considering neither of the values are saved but the above would copy from left to right.

Clone this wiki locally