refactor: Remove ForEach discovery, cache MethodInfo

Remove ForEach type argument collection from source generator.
Cache MethodInfo for RemoveComponentImpl in World.cs.
Update API docs for IRelationship and ChangeKind.
This commit is contained in:
hyper
2026-07-22 16:14:58 +08:00
parent 8a32588c54
commit 53fa3b742d
3 changed files with 15 additions and 86 deletions
+9 -11
View File
@@ -194,6 +194,11 @@ public class World : IDisposable
nameof(AddComponentImpl),
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)!;
private static readonly System.Reflection.MethodInfo s_removeComponentImpl =
typeof(World).GetMethod(
nameof(RemoveComponentImpl),
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)!;
private void AddComponentImpl<T>(Entity entity, T component) where T : struct
{
ThrowIfNotAlive(entity);
@@ -589,20 +594,13 @@ public class World : IDisposable
switch (m.Kind)
{
case PendingMutationKind.AddComponent:
// Use reflection to call AddComponentImpl<T>.
var addMethod = typeof(World).GetMethod(
nameof(AddComponentImpl),
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)!;
var genericAdd = addMethod.MakeGenericMethod(m.ComponentType);
genericAdd.Invoke(this, [m.Entity, m.Component]);
s_addComponentImpl.MakeGenericMethod(m.ComponentType)
.Invoke(this, [m.Entity, m.Component]);
break;
case PendingMutationKind.RemoveComponent:
var removeMethod = typeof(World).GetMethod(
nameof(RemoveComponentImpl),
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)!;
var genericRemove = removeMethod.MakeGenericMethod(m.ComponentType);
genericRemove.Invoke(this, [m.Entity]);
s_removeComponentImpl.MakeGenericMethod(m.ComponentType)
.Invoke(this, [m.Entity]);
break;
case PendingMutationKind.DestroyEntity: