Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting to a custom type #97

Open
Pale-Gray opened this issue Feb 9, 2025 · 0 comments
Open

Converting to a custom type #97

Pale-Gray opened this issue Feb 9, 2025 · 0 comments

Comments

@Pale-Gray
Copy link

Pale-Gray commented Feb 9, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant