15 private Func<TagCompound, T> deserializer;
17 public TagSerializableSerializer() {
19 var field = type.GetField(
"DESERIALIZER");
21 if (field.FieldType != typeof(Func<TagCompound, T>))
22 throw new ArgumentException(
23 $
"Invalid deserializer field type {field.FieldType} in {type.FullName} expected {typeof(Func<TagCompound, T>)}.");
25 deserializer = (Func<TagCompound, T>)field.GetValue(null);
30 var tag = value.SerializeData();
31 tag[
"<type>"] = value.GetType().FullName;
37 var instType = GetType(tag.
GetString(
"<type>"));
39 if (instType != null && Type.IsAssignableFrom(instType) && TryGetSerializer(instType, out instSerializer))
40 return (T)instSerializer.Deserialize(tag);
43 if (deserializer == null)
44 throw new ArgumentException($
"Missing deserializer for type '{Type.FullName}'.");
46 return deserializer(tag);
string GetString(string key)
bool ContainsKey(string key)