-
-
Notifications
You must be signed in to change notification settings - Fork 3
Batch types registration
Use RuntimeTypeModel.Add(Assembly)
or Add(Type[])
to add all types (marked with attributes) with all dependencies included.
This can be especially usable when you prepare your model for compilation.
Because subtypes have automatically generated field numbers (when not specified explicitly) it's required to export/import them if you want your RuntimeTypeModel
s to "understand" each other: Serialize(ExportTypeRelations())
- ImportTypeRelations(Deserialize())
. All the subtypes are imported in the correct order so they have the same field numbers as in their original model.
Remember that the import/export functionality does not synchronize field numbers but only subtypes. The point of this is the fact that field numbers don't depend on the type adding order but subtype numbers do. The forceDefaultBehavior
allows to add fields with their field numbers the same way as MetaType.ApplyDefaultBehavior()
does. If you don't need to register any fields or want to add them manually pass false
to this parameter.
As an alternative you can just add types in the same order for both RuntimeTypeModels
or specify derived types field numbers with SerializeDerivedType
attribute. RuntimeTypeModel.Add(Assembly)
automatically sorts types by FullName
so they are added in the same order each time.
Precompilation bakes subtype numbers into dll so import/export is only needed for RuntimeTypeModel
.