OneOf icon indicating copy to clipboard operation
OneOf copied to clipboard

Please can you add a source generator for value typed OneOf?

Open jamescarter-le opened this issue 1 year ago • 1 comments

It would be great to have OneOf source generators for struct.

Something like:

[GenerateOneOf(typeof(String), typeof(Int)]
public readonly partial struct MyStruct {}
public readonly partial struct MyStruct {
    private readonly String _value0;
    private readonly Int _value1;
    private readonly int _index;
    
    public IsString => ...
    public IsInt => ...
    
    public string AsString => ...
    public int AsInt => ...
}

jamescarter-le avatar Jul 22 '24 14:07 jamescarter-le

This looks close to how I built my union library https://github.com/AterraEngine/unions-cs as it is fully built on using ValueTypes. There is a lot of performance gained with how I approached it, maybe something OneOf can definitly implement?

AnnaSasDev avatar Dec 10 '24 13:12 AnnaSasDev