void ActivateSchema(Schema schema) { // What schema changes are relevant to us? // - Schema of own type // - Schema of value-types inside us (dispatches for ref types are handled by RefFormatter anyway) // For now we only adapt to change to the current type schema. // Do we have serializers prepared for this schema already? // Important sanity check, if this happens the user should definitely know about it! if (_deserializationDepth > 0) { if (schema.Type.IsValueType) { throw new InvalidOperationException("Schema of a value-type has changed while an object-type is being deserialized. This is feature is WIP, check out GitHub for more information."); } } // Use already compiled serializers if (_generatedSerializerPairs.TryGetValue(schema, out var pair)) { _serializer = pair.Serializer; _deserializer = pair.Deserializer; _currentSchema = schema; return; } bool isStatic = schema.IsStatic; // Generate if (schema.IsPrimary) { _serializer = DynamicFormatter <T> .GenerateSerializer(_ceras, schema, true, isStatic).Compile(); _deserializer = DynamicFormatter <T> .GenerateDeserializer(_ceras, schema, true, isStatic).Compile(); } else { // Different Schema -> generate no serializer! // Writing data in some old format is not supported (yet, maybe in the future). // In theory we could do it. But it's not implemented because there would have to be some way for the user to specify what Schema to use. // And we get into all sorts of troubles with type-conversion (not implemented yet, but it will probably arrive earlier than this...) // This also protects us against bugs! _serializer = ErrorSerializer; _deserializer = DynamicFormatter <T> .GenerateDeserializer(_ceras, schema, true, isStatic).Compile(); } _currentSchema = schema; _generatedSerializerPairs.Add(schema, new SerializerPair(_serializer, _deserializer)); }