Open levicki opened 4 months ago
To clarify, doing serialization using Newtonsoft.JSON
produces the following output:
Example 1
Example 2
Workaround for the problem (partial, very inelegant, and without error handling):
TomletMain.RegisterMapper<Dictionary<string, dynamic>>(
s => {
TomlTable Result = new TomlTable();
foreach (var kvp in s) {
TomlValue Value = null;
TypeCode tc = Type.GetTypeCode(kvp.Value.GetType());
switch (tc) {
case TypeCode.Boolean:
Value = TomlBoolean.ValueOf(kvp.Value);
break;
case TypeCode.Byte:
case TypeCode.SByte:
case TypeCode.Int16:
case TypeCode.UInt16:
case TypeCode.Int32:
case TypeCode.UInt32:
case TypeCode.Int64:
case TypeCode.UInt64:
Value = new TomlLong(kvp.Value);
break;
case TypeCode.Single:
case TypeCode.Double:
case TypeCode.Decimal:
Value = new TomlDouble(kvp.Value);
break;
case TypeCode.DateTime:
Value = new TomlLocalDateTime(kvp.Value);
break;
case TypeCode.String:
case TypeCode.Char:
Value = new TomlString(kvp.Value);
break;
default:
// TODO: throw proper exception about type unsupported by TOML
break;
}
Result.PutValue(kvp.Key, Value);
}
return Result;
},
d => {
Dictionary<string, dynamic> Result = new Dictionary<string, dynamic>();
TomlDocument doc = d as TomlDocument;
foreach (var kvp in doc) {
Result.Add(kvp.Key, kvp.Value);
}
return Result;
}
);
Let's start with simple stuff:
This produces the following exception:
If you do not wrap the
Dictionary<string, dynamic>
into aGameState
class but put it as a top object for serialization:Serialization kind of works (i.e. doesn't crash), but produces nonsensical / useless output:
Am I wrong expecting this to produce proper values at the TOML file level outside of any table instead of bunch of empty inline tables?
Also, I expected the first case with
GameVars
inside ofGameState
class to produce:Hopefully this is easy to fix?