Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add overload for AddComponent method that takes an instance value #425

Closed
duydang2311 opened this issue Jan 14, 2023 · 0 comments · Fixed by #427
Closed

Add overload for AddComponent method that takes an instance value #425

duydang2311 opened this issue Jan 14, 2023 · 0 comments · Fixed by #427

Comments

@duydang2311
Copy link
Contributor

duydang2311 commented Jan 14, 2023

There are two overloads for AddComponent method, and they are not so convenient to use.

T AddComponent<T>(EntityId entity) where T : Component;
T AddComponent<T>(EntityId entity, params object[] args) where T : Component;

Using params object[] args destroys the whole advantages of having language server intelli-sense. There are no suggestions on what we can pass into the arguments.
Besides, this using reflection to create instance is also a bit slower.

Instead, I'd suggest adding this overload:

T AddComponent<T>(EntityId entity, T value) where T : Component;

The method becomes much more shorter and nicer to use, considering the example below:

public class MyComponent : Component
{
    public long Id { get; set; }
    public string Name { get; set; }
}

AddComponent(entity, new Component() { Id = 1, Name = "abc" });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant