Skip to content

Cannot use language keywords as the name of a component #1032

@PopSlime

Description

@PopSlime

Describe the bug

When language keywords like Event are used as the name of a component, the code generator fails to handle the component name correctly.

To Reproduce

Generate code for the following component.

[Game]
public sealed class EventComponent : IComponent {
	public MyEvent Event;
}

Generated code:

public partial class GameEntity {

    public EventComponent event { get { return (EventComponent)GetComponent(GameComponentsLookup.Event); } }
    // ...
}

Compilation error:

Assets\Generated\Game\Components\EventComponent.cs: error CS1519: Invalid token 'event' in class, record, struct, or interface member declaration

Potential Solution

Prefix the component name with a verbatim identifier @ if it is a language keyword. For example, event becomes @event.

Entitas Version

  • Entitas 1.14.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions