mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-09-08 01:32:08 +02:00
Allow static json converters to write null values
This commit is contained in:
parent
498e1d8fe6
commit
ecc0c3b963
2 changed files with 6 additions and 2 deletions
|
@ -63,7 +63,7 @@ Improvements
|
|||
### MLEM.Data
|
||||
Improvements
|
||||
- **Moved extension methods into matching namespaces to avoid unexpected suggestions**
|
||||
- Allow static json converters to throw an exception if a key does not exist
|
||||
- Allow static json converters to write null values and to throw an exception if a key does not exist
|
||||
|
||||
Removals
|
||||
- **Removed obsolete types DynamicEnumConverter, CopyExtensions, DynamicEnum, NetBufferSerializer, and NetExtensions**
|
||||
|
|
|
@ -58,8 +58,12 @@ namespace MLEM.Data.Json {
|
|||
/// <param name="value">The value.</param>
|
||||
/// <param name="serializer">The calling serializer.</param>
|
||||
public override void WriteJson(JsonWriter writer, T value, JsonSerializer serializer) {
|
||||
if (value == null) {
|
||||
writer.WriteNull();
|
||||
return;
|
||||
}
|
||||
if (!this.inverse.TryGetValue(value, out var key))
|
||||
throw new InvalidOperationException($"Cannot write {value} that is not a registered entry");
|
||||
throw new KeyNotFoundException($"Cannot write {value} that is not a registered entry");
|
||||
writer.WriteValue(key);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue