hadashiA / VYaml

The extra fast, low memory footprint YAML library for C#, focued on .NET and Unity.
MIT License
295 stars 16 forks source link

Problem with nullable dictionary #109

Closed rube200 closed 1 month ago

rube200 commented 1 month ago

Hi, i am trying to move from YamlDotNet to VYaml, but i am getting an hard time. Currently it forces me to manually create formatters instead of using YamlObject annotation. When i have Dictionary<string, object?>? data; it seems to not work, i got compilling error CS8619, looking at the pre gen code it creates internal var var __Data__ = default(global::System.Collections.Generic.Dictionary<string, object>) instead of the requested type.

The problem seems to be Dictionary<string, object> instead of Dictionary<string, object?>

rube200 commented 1 month ago

Also everything works fine when a manully format it based on gen code

hadashiA commented 1 month ago

I tried it at hand and the following samples worked.

[YamlObject]
public partial class DictionaryMember
{
    public Dictionary<string, object?>? Data { get; set; }
}

Can you give me the specific code that reproduces the problem?

rube200 commented 1 month ago

Did you enable nullability? We have it in error mode I am one of maintainers of OpenMod, I am currently porting it from YamlDotNet to VYaml, if you really need I can try making an sample.

hadashiA commented 1 month ago

Ah, maybe I understand the problem.

If Data is non-nullable, does that mean the following assign will give a warning?

    Data = __Data__

Ok, I've fixed in #110.

rube200 commented 1 month ago

If Data is non-nullable, does that mean the following assign will give a warning?

Yes I think that is the problem, in our case we get compilation error since we treat that warn as error.

rube200 commented 1 month ago

Also can you add HashSet/Set ? To resolvers? It is very similar to list.

hadashiA commented 1 month ago

Also can you add HashSet/Set ? To resolvers?

111 I was just working on. I'll release it soon.

I hope you'll give it a try.