+
Skip to content

Converting to a custom type #97

@Pale-Gray

Description

@Pale-Gray

Hello,

I recently picked this up to try to deserialize TOML, however, I am having trouble with deserializing into custom types.
I have this current setup, trying to deserialize an array into a Vector3:

TomlModelOptions op = new TomlModelOptions();
op.ConvertToModel = (o, toType) =>
{
    Console.WriteLine(toType);
    if (toType == typeof(DateTime)) return new DateTime();
    if (o.GetType() == typeof(List<>) && toType == typeof(Vector3)) return new Vector3();
    return null;
};
Toml.ToModel<PrimitiveModelData>(File.ReadAllText(tomlFile), options: op);

however, I end up getting an error when i try to deserialize, stating: Invalid list type OpenTK.Mathematics.Vector3. Getting a StandardObjectDynamicAccessor Type: OpenTK.Mathematics.Vector3 instead.

My toml file is simply

[[cubes]]
start = [0, 0, 0]

Note that it does work for DateTime (Console.WriteLine prints), but doesn't work for the custom type. How could I fix this? Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载