Skip to content

Replace code generators with C# 14 extensions #81

Open
@BeanCheeseBurrito

Description

@BeanCheeseBurrito

The extension code generators should be replaced with the C# 14 extensions feature when it lands. This will get rid of about 400,000 lines of generated code and make the wrapper significantly easier to maintain and contribute to as we will only have to write extension methods once and have it be usable by many types.
https://github.com/dotnet/csharplang/blob/main/proposals/extensions.md

public struct Entity : IEntity { ... }
public struct Component<T> : IEntity { ... }
public struct System<T, ...> : IEntity { ... }
public struct Observer<T, ...> : IEntity { ... }

public static class EntityMethods
{
    // All types that implement the IEntity interface will receive .Get and .Set methods.
    extension<T> (T entity) where T : IEntity
    {
        public ref TComponent Get<TComponent>()
        {
            ...
        }
        
        public ref T Set<TComponent>(TComponent value)
        {
            ...
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions