applejag / Newtonsoft.Json-for-Unity

Newtonsoft.Json (Json.NET) 10.0.3, 11.0.2, 12.0.3, & 13.0.1 for Unity IL2CPP builds, available via Unity Package Manager
https://github.com/jilleJr/Newtonsoft.Json-for-Unity
MIT License
1.15k stars 128 forks source link

Suggestion: AOTHelper methods with type parameter #41

Closed hhhmmmmmm closed 4 years ago

hhhmmmmmm commented 4 years ago

https://github.com/jilleJr/Newtonsoft.Json-for-Unity/wiki/Reference-Newtonsoft.Json.Utilities.AotHelper

It would be nice to have AOTHelper methods with Type parameter in addition to the generic version. My use case is I have a collection of types, and I want to ensure lists exist for every one of them, so calling EnsureList(Type type) instead of EnsureList() would be better in this situation.

Nice work, by the way! I'm glad to have found this.

applejag commented 4 years ago

I'm sorry to say that this cannot be done :(

The AotHelper works just because it's generic. It's magic comes from tricking the compiler on generating the types specified from the generic type parameter. Something that cannot be done with regular type parameters.

You will have to specify all the types that will be used explicitly via the AotHelper or via link.xml.