Replies: 1 comment 4 replies
-
Ok, so I see some upvotes, and no comments against it, so perhaps it's worth putting a bit more thought to it. The biggest problem with proposed approach is (de)serializer function declaration conflict when using e.g. C# addons which declare them for same types (e.g. System.Collections) as the main project. This could be fixed with attributes, but needs extra thought. I think that specifying attributes per-member would litter the class and make it less readable, but perhaps a per-class attribute would do the trick: namespace MyAwesomeProject
{
[GlobalClass]
[SerializerNamespace="MyAwesomeProject.Utility"]
public partial class TestResource : Resource
{
[Export]
public int intProp = 5;
[Export]
public List<ClassInOtherLibrary> listProp = new(); // Currently throws GD0102
}
}
// Perhaps in other file:
namespace MyAwesomeProject.Utility
{
public partial class Serializer
{
public static Error Serialize<[MustBeVariant] T>(List<T> data, out Variant serializedData)
where T : class
{
// ...
}
public static Error Serialize<[MustBeVariant] T>(Variant serializedData, out List<T> data)
{
// ...
}
}
} I assume that ClassInOtherLibrary would have its own One small minus is that The thing of my most concern for this solution would be NativeAOT support. Being a C# novice, I assume that parsing attributes would involve reflection, which might not play nice with AOT, so perhaps it's a showstopper. Unless this would only use reflection on GodotSharp side to run proper source generators... Thoughts? |
Beta Was this translation helpful? Give feedback.
-
It'd be best to be able to fix GD0102 for every C# type, not only System.Collections. How about adding means of being able to define custom (de)serializers for given type/field by implementing custom (de)serializers?
There are some problems needing ironing out like duplicate (de)serializers for given type in case of attaching multiple addons to the project, but some reasonable solutions could be found, I think.
Would that thing be even doable in current c# backend? I'm willing to writing proper proposal and help adding this stuff in if someone from the team at least initially green-lights it.
Beta Was this translation helpful? Give feedback.
All reactions