Skip to content

Changing auto add behavior

Vladyslav Taranov edited this page Nov 3, 2015 · 17 revisions

When AqlaSerializer meets unknown type it tries to recognize it automatically the same way as RuntimeTypeMode.Add(type, true) does. The behavior of auto-adding was refactored out from the core and can be extended now. E.g. this includes adding new attributes.

You can get or set the current IAutoAddStrategy with RuntimeTypeModel.AutoAddStrategy.

The default strategy can be casted to DefaultAutoAddStrategy so you can alter its behavior by modifying its properties.

By default subtypes are automatically registered to their base types as with ProtoInclude attribute (if they were not registered before). All member types are automatically registered too.

The ImplicitFallbackMode property allows you to setup ImplicitFields behavior for not recognized types (which don't have attributes and can't be treated as tuples).

Look via IntelliSense to find other additional settings.

You can create your own IAutoAddStrategy and inject it into model (AutoAddStrategy property). You can even support any custom attributes. Note that it's required to inherit from DefaultAutoAddStrategy so you have access to some important protected methods. To avoid unpredictable side effects please don't try to hot-swap AutoAddStrategy between adding related (via inheritance or composition) types.

System.Serializable attribute

You can enable System.Serializable attribute support by modifying DefaultAutoAddStrategy.AcceptableAttributes property. For this attribute ImplicitFields.AllFields mode is used.

Clone this wiki locally