diff --git a/src/EcsQuery/EcsQueryDI.cs b/src/EcsQuery/EcsQueryDI.cs index 4b9354f..23c7f53 100644 --- a/src/EcsQuery/EcsQueryDI.cs +++ b/src/EcsQuery/EcsQueryDI.cs @@ -3,7 +3,7 @@ using System.Reflection; namespace DCFApixels.DragonECS { - public abstract class EcsJoinQueryDI : EcsJoinAttachQuery + public abstract class EcsJoinAttachQueryDI : EcsJoinAttachQuery where TAttachComponent : struct, IEcsAttachComponent { protected override void Init(Builder b) => EcsQueryDIHelper.Fill(this, b); @@ -22,8 +22,6 @@ namespace DCFApixels.DragonECS MethodInfo excludeMethod = builderType.GetMethod("Exclude", BindingFlags.Instance | BindingFlags.Public); MethodInfo optionalMethod = builderType.GetMethod("Optional", BindingFlags.Instance | BindingFlags.Public); - //PropertyInfo componentTypeProp = builderType.GetProperty("ComponentType", BindingFlags.Instance | BindingFlags.Public); - Type thisType = q.GetType(); FieldInfo[] fieldInfos = thisType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fieldInfos) @@ -31,12 +29,9 @@ namespace DCFApixels.DragonECS Type fieldType = fieldInfo.FieldType; if (fieldType.IsSubclassOf(typeof(EcsPoolBase)) == false) continue; - if (fieldType.IsGenericType == false) continue; - //Type fiedlTypeDefinition = fieldType.GetGenericTypeDefinition(); - //Type componentType = ((EcsPoolBase)componentTypeProp.GetValue(fieldInfo.GetValue(q))).ComponentType; Type componentType = fieldType.GenericTypeArguments[0]; if (fieldInfo.GetCustomAttribute() != null) @@ -49,7 +44,11 @@ namespace DCFApixels.DragonECS fieldInfo.SetValue(q, excludeMethod.MakeGenericMethod(componentType, fieldType).Invoke(b, null)); continue; } - fieldInfo.SetValue(q, optionalMethod.MakeGenericMethod(componentType, fieldType).Invoke(b, null)); + if (fieldInfo.GetCustomAttribute() != null) + { + fieldInfo.SetValue(q, optionalMethod.MakeGenericMethod(componentType, fieldType).Invoke(b, null)); + continue; + } } } }