In .NET, it is possible to create fully dynamic objects. This makes it possible to create types of which the members are not yet known at compile time. Starting with Catel 3.7, the DynamicModelBase is fully dynamic and still provides the features such as serialization. Catel supports dynamic objects by implementing the IDynamicMetaObjectProvider which is available in WPF, Silverlight and Windows RT.
For more information about dynamic programming, see MSDN
Creating dynamic objects
Creating a dynamic object with full Catel functionality is easy. Just add the Catel.Extensions.DynamicObjects reference via NuGet and create a class that derives from DynamicModelBase:
Then the dynamic model can be used like this:
It is important to know that you must use the keyword dynamic to instantiate the type.
Using ModelBase functionality
The DynamicModelBase class derives from ModelBase. However it must be preceded by the dynamic keyword. To use the ModelBase functionality, cast it to the right type:
Supporting serialization of dynamic objects
Dynamic objects in Catel fully support the default serialization that Catel provides. To example below shows how to serialize a dynamic object: