From 034b6c0fa7f635755a2d5b4067e84e47ec1e7ff4 Mon Sep 17 00:00:00 2001 From: "Dylan R. E. Moonfire" Date: Wed, 6 Jul 2022 01:34:51 -0500 Subject: [PATCH] feat: refactoring for more consistent naming --- src/Gallium.Tests/EnumerableEntityTests.cs | 120 ++++-------- src/Gallium.Tests/Gallium.Tests.csproj | 2 +- src/Gallium/Entity.cs | 139 +++++++++++++- src/Gallium/EnumerableEntityExtensions.cs | 109 ----------- src/Gallium/EnumerableEntityExtensions1.cs | 68 ------- src/Gallium/ForEntityExtensions.cs | 92 ++++++++++ src/Gallium/Gallium.csproj | 2 +- src/Gallium/SelectEntityExtensions.cs | 171 ++++++++++++++++++ src/Gallium/WhereAllComponentsExtensions.cs | 34 ++++ src/Gallium/WhereComponentsExtensions.cs | 54 ++++++ src/Gallium/WhereNotAllComponentExtensions.cs | 44 +++++ 11 files changed, 567 insertions(+), 268 deletions(-) delete mode 100644 src/Gallium/EnumerableEntityExtensions.cs delete mode 100644 src/Gallium/EnumerableEntityExtensions1.cs create mode 100644 src/Gallium/ForEntityExtensions.cs create mode 100644 src/Gallium/SelectEntityExtensions.cs create mode 100644 src/Gallium/WhereAllComponentsExtensions.cs create mode 100644 src/Gallium/WhereComponentsExtensions.cs create mode 100644 src/Gallium/WhereNotAllComponentExtensions.cs diff --git a/src/Gallium.Tests/EnumerableEntityTests.cs b/src/Gallium.Tests/EnumerableEntityTests.cs index 7901c7d..3795bc4 100644 --- a/src/Gallium.Tests/EnumerableEntityTests.cs +++ b/src/Gallium.Tests/EnumerableEntityTests.cs @@ -11,21 +11,15 @@ namespace Gallium.Tests { Entity[] entities = { - new Entity() - .Add("1") - .Add(new TestComponent1()), - new Entity() - .Add("2") - .Add(new TestComponent2()), - new Entity() - .Add("3") - .Add(new TestComponent1()), + new Entity().Add("1").Add(new TestComponent1()), + new Entity().Add("2").Add(new TestComponent2()), + new Entity().Add("3").Add(new TestComponent1()), }; Assert.Equal( new[] { "1!", "2", "3!" }, entities - .ForEachEntity( + .ForEntity( (e, _) => e.Set(e.Get() + "!")) .Select(x => x.Get()) .ToArray()); @@ -36,14 +30,9 @@ namespace Gallium.Tests { Entity[] entities = { - new Entity() - .Add("1") - .Add(new TestComponent1()), - new Entity() - .Add("2") - .Add(new TestComponent2()), - new Entity() - .Add("3") + new Entity().Add("1").Add(new TestComponent1()), + new Entity().Add("2").Add(new TestComponent2()), + new Entity().Add("3") .Add(new TestComponent1()) .Add(new TestComponent2()), }; @@ -51,7 +40,7 @@ namespace Gallium.Tests Assert.Equal( new[] { "1", "2", "3!" }, entities - .ForEachEntity( + .ForEntity( (e, _, _) => e.Set(e.Get() + "!")) .Select(x => x.Get()) .ToArray()); @@ -62,15 +51,11 @@ namespace Gallium.Tests { Entity[] entities = { - new Entity() - .Add("1") - .Add(new TestComponent1()), - new Entity() - .Add("2") + new Entity().Add("1").Add(new TestComponent1()), + new Entity().Add("2") .Add(new TestComponent2()) .Add(new TestComponent3b()), - new Entity() - .Add("3") + new Entity().Add("3") .Add(new TestComponent3a()) .Add(new TestComponent1()) .Add(new TestComponent2()), @@ -79,8 +64,7 @@ namespace Gallium.Tests Assert.Equal( new[] { "1", "2", "3-TestComponent3a" }, entities - .ForEachEntity( + .ForEntity( (e, _, _, t) => e.Set( e.Get() + "-" + t.GetType().Name)) .Select(x => x.Get()) @@ -92,21 +76,14 @@ namespace Gallium.Tests { Entity[] entities = { - new Entity() - .Add("1") - .Add(new TestComponent1()), - new Entity() - .Add("2") - .Add(new TestComponent2()), - new Entity() - .Add("3") - .Add(new TestComponent1()), + new Entity().Add("1").Add(new TestComponent1()), + new Entity().Add("2").Add(new TestComponent2()), + new Entity().Add("3").Add(new TestComponent1()), }; Assert.Equal( new[] { "1", "3" }, - entities - .HasComponents() + entities.WhereAllComponents() .Select(x => x.Get()) .ToArray()); } @@ -116,22 +93,16 @@ namespace Gallium.Tests { Entity[] entities = { - new Entity() - .Add("1") - .Add(new TestComponent1()), - new Entity() - .Add("2") + new Entity().Add("1").Add(new TestComponent1()), + new Entity().Add("2") .Add(new TestComponent2()) .Add(new TestComponent1()), - new Entity() - .Add("3") - .Add(new TestComponent1()), + new Entity().Add("3").Add(new TestComponent1()), }; Assert.Equal( new[] { "2" }, - entities - .HasComponents() + entities.WhereAllComponents() .Select(x => x.Get()) .ToArray()); } @@ -141,24 +112,21 @@ namespace Gallium.Tests { Entity[] entities = { - new Entity() - .Add("1") + new Entity().Add("1") .Add(new TestComponent1()) .Add(new TestComponent3b()) .Add(new TestComponent2()), - new Entity() - .Add("2") + new Entity().Add("2") .Add(new TestComponent2()) .Add(new TestComponent1()), - new Entity() - .Add("3") + new Entity().Add("3") .Add(new TestComponent3a()), }; Assert.Equal( new[] { "1" }, entities - .HasComponents() .Select(x => x.Get()) .ToArray()); @@ -169,21 +137,14 @@ namespace Gallium.Tests { Entity[] entities = { - new Entity() - .Add("1") - .Add(new TestComponent1()), - new Entity() - .Add("2") - .Add(new TestComponent2()), - new Entity() - .Add("3") - .Add(new TestComponent1()), + new Entity().Add("1").Add(new TestComponent1()), + new Entity().Add("2").Add(new TestComponent2()), + new Entity().Add("3").Add(new TestComponent1()), }; Assert.Equal( new[] { "2" }, - entities - .NotComponents() + entities.WhereNotComponent() .Select(x => x.Get()) .ToArray()); } @@ -193,21 +154,16 @@ namespace Gallium.Tests { Entity[] entities = { - new Entity() - .Add("1") - .Add(new TestComponent1()), - new Entity() - .Add("2") + new Entity().Add("1").Add(new TestComponent1()), + new Entity().Add("2") .Add(new TestComponent2()) .Add(new TestComponent1()), - new Entity() - .Add("3"), + new Entity().Add("3"), }; Assert.Equal( new[] { "1", "3" }, - entities - .NotComponents() + entities.WhereNotAllComponents() .Select(x => x.Get()) .ToArray()); } @@ -217,23 +173,19 @@ namespace Gallium.Tests { Entity[] entities = { - new Entity() - .Add("1") - .Add(new TestComponent1()), - new Entity() - .Add("2") + new Entity().Add("1").Add(new TestComponent1()), + new Entity().Add("2") .Add(new TestComponent1()) .Add(new TestComponent2()) .Add(new TestComponent3b()), - new Entity() - .Add("3") + new Entity().Add("3") .Add(new TestComponent3a()), }; Assert.Equal( new string[] { "1", "3" }, entities - .NotComponents() .Select(x => x.Get()) .ToArray()); diff --git a/src/Gallium.Tests/Gallium.Tests.csproj b/src/Gallium.Tests/Gallium.Tests.csproj index 0c0bc6b..db36b93 100644 --- a/src/Gallium.Tests/Gallium.Tests.csproj +++ b/src/Gallium.Tests/Gallium.Tests.csproj @@ -1,7 +1,7 @@ - net5.0 + net6.0 false enable Gallium.Tests diff --git a/src/Gallium/Entity.cs b/src/Gallium/Entity.cs index bcdd4ca..a3d5078 100644 --- a/src/Gallium/Entity.cs +++ b/src/Gallium/Entity.cs @@ -57,11 +57,76 @@ namespace Gallium /// Gets a value indicating whether the entity has a specific type of /// component registered. /// - /// The component type. + /// The component type. /// True if the type exists, otherwise false. - public bool Has() + public bool Has() { - return this.Has(typeof(TType)); + return this.Has(typeof(T1)); + } + + /// + /// Gets a value indicating whether the entity has components of the given types + /// registered. + /// + /// The first component type. + /// + /// True if there are components of the given type exists, otherwise + /// false. + /// + public bool HasAll() + { + return this.Has(); + } + + /// + /// Gets a value indicating whether the entity has components of the given types + /// registered. + /// + /// The first component type. + /// The second component type. + /// + /// True if there are components of the given type exists, otherwise + /// false. + /// + public bool HasAll() + { + return this.Has() && this.Has(); + } + + /// + /// Gets a value indicating whether the entity has components of the given types + /// registered. + /// + /// The first component type. + /// The second component type. + /// The third component type. + /// + /// True if there are components of the given type exists, otherwise + /// false. + /// + public bool HasAll() + { + return this.Has() && this.Has() && this.Has(); + } + + /// + /// Gets a value indicating whether the entity has components of the given types + /// registered. + /// + /// The first component type. + /// The second component type. + /// The third component type. + /// The third component type. + /// + /// True if there are components of the given type exists, otherwise + /// false. + /// + public bool HasAll() + { + return this.Has() + && this.Has() + && this.Has() + && this.Has(); } /// @@ -104,7 +169,7 @@ namespace Gallium /// /// Gets the given component type if inside the entity, otherwise the - /// default avlue. + /// default value. /// /// The component type. /// The found component or default (typically null). @@ -145,7 +210,7 @@ namespace Gallium /// True if found, otherwise false. public bool TryGet(out T1 value1, out T2 value2) { - if (this.Has() && this.Has()) + if (this.HasAll()) { value1 = this.Get(); value2 = this.Get(); @@ -157,6 +222,70 @@ namespace Gallium return false; } + /// + /// Attempts to get the values, if present. If not, this returns false + /// and the value is undefined. Otherwise, this method returns true + /// and the actual value inside that variable. + /// + /// The value if contained in the entity. + /// The value if contained in the entity. + /// The first component type. + /// The second component type. + /// The third component type. + /// True if found, otherwise false. + public bool TryGet( + out T1 value1, + out T2 value2, + out T3 value3) + { + if (this.HasAll()) + { + value1 = this.Get(); + value2 = this.Get(); + value3 = this.Get(); + return true; + } + + value1 = default!; + value2 = default!; + value3 = default!; + return false; + } + + /// + /// Attempts to get the values, if present. If not, this returns false + /// and the value is undefined. Otherwise, this method returns true + /// and the actual value inside that variable. + /// + /// The value if contained in the entity. + /// The value if contained in the entity. + /// The first component type. + /// The second component type. + /// The third component type. + /// The fourth component type. + /// True if found, otherwise false. + public bool TryGet( + out T1 value1, + out T2 value2, + out T3 value3, + out T4 value4) + { + if (this.HasAll()) + { + value1 = this.Get(); + value2 = this.Get(); + value3 = this.Get(); + value4 = this.Get(); + return true; + } + + value1 = default!; + value2 = default!; + value3 = default!; + value4 = default!; + return false; + } + /// /// Sets the component in the entity, regardless if there was a /// component already registered. diff --git a/src/Gallium/EnumerableEntityExtensions.cs b/src/Gallium/EnumerableEntityExtensions.cs deleted file mode 100644 index 84296f6..0000000 --- a/src/Gallium/EnumerableEntityExtensions.cs +++ /dev/null @@ -1,109 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using EE = System.Collections.Generic.IEnumerable; - -namespace Gallium -{ - public static class EnumerableEntityExtensions - { - public static EE ForEachEntity( - this EE entities, - Func lambda) - { - return entities - .Select( - x => !x.Has() || !x.Has() - ? x - : lambda(x, x.Get(), x.Get())); - } - - public static EE ForEachEntity( - this EE entities, - Func lambda) - { - return entities - .Select( - x => !x.Has() || !x.Has() || !x.Has() - ? x - : lambda(x, x.Get(), x.Get(), x.Get())); - } - - public static EE ForEntities( - this EE entities, - Func lambda) - { - List list = entities.ToList(); - EE has = lambda(list.HasComponents()); - EE hasNot = list.NotComponents(); - - return hasNot.Union(has); - } - - public static EE ForEntities( - this EE entities, - Func lambda) - { - List list = entities.ToList(); - EE has = lambda(list.HasComponents()); - EE hasNot = list.NotComponents(); - - return hasNot.Union(has); - } - - public static EE ForEntities( - this EE entities, - Func lambda) - { - List list = entities.ToList(); - EE has = lambda(list.HasComponents()); - EE hasNot = list.NotComponents(); - - return hasNot.Union(has); - } - - public static EE HasComponents(this EE entities) - { - return entities - .Where(x => x.Has() && x.Has()); - } - - public static EE HasComponents(this EE entities) - { - return entities - .Where(x => x.Has() && x.Has() && x.Has()); - } - - public static EE HasComponents(this EE entities) - { - return entities - .Where( - x => x.Has() - && x.Has() - && x.Has() - && x.Has()); - } - - public static EE NotComponents(this EE entities) - { - return entities - .Where(x => !x.Has() || !x.Has()); - } - - public static EE NotComponents(this EE entities) - { - return entities - .Where(x => !x.Has() || !x.Has() || !x.Has()); - } - - public static EE NotComponents(this EE entities) - { - return entities - .Where( - x => !x.Has() - || !x.Has() - || !x.Has() - || !x.Has()); - } - } -} diff --git a/src/Gallium/EnumerableEntityExtensions1.cs b/src/Gallium/EnumerableEntityExtensions1.cs deleted file mode 100644 index 34b2eda..0000000 --- a/src/Gallium/EnumerableEntityExtensions1.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using EE = System.Collections.Generic.IEnumerable; - -namespace Gallium -{ - public static class EnumerableEntityExtensions1 - { - public static EE ForEachEntity( - this EE entities, - Func lambda) - { - return entities - .Select(x => x.Has() ? lambda(x, x.Get()) : x); - } - - /// - /// Runs an inner set of operation for entities that have a specific - /// component. - /// - /// The input to scan. - /// - /// The list operation for the ones that have those - /// components. - /// - /// The type of the first component. - /// - /// A combined list of components, with entities without the component - /// coming first and the ones with the component coming last after being - /// processed by the lambda. - /// - public static EE ForEntities( - this EE entities, - Func lambda) - { - List list = entities.ToList(); - EE has = lambda(list.HasComponents()); - EE hasNot = list.NotComponents(); - - return hasNot.Union(has); - } - - public static EE HasComponents(this EE entities) - { - return entities - .Where(x => x.Has()); - } - - public static EE NotComponents(this EE entities) - { - return entities - .Where(x => !x.Has()); - } - - public static EE WhereEntities( - this EE entities, - Func lambda, - bool includeWithoutComponent = true) - { - return entities - .Where( - x => x.Has() - ? lambda(x, x.Get()) - : includeWithoutComponent); - } - } -} diff --git a/src/Gallium/ForEntityExtensions.cs b/src/Gallium/ForEntityExtensions.cs new file mode 100644 index 0000000..a73823d --- /dev/null +++ b/src/Gallium/ForEntityExtensions.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; + +namespace Gallium +{ + public static class ForEntityExtensions + { + /// + /// Selects an entity from the given list, filtering on entities with + /// the given components. If the entity doesn't match, it is passed as it. + /// + /// The entities to parse. + /// + /// The transformation function for the entity + /// and selected components. If this returns null, then the entity will be filtered + /// out. + /// + /// The type of the first component. + /// An enumeration of transformed entities. + public static IEnumerable ForEntity( + this IEnumerable entities, + Func selectWithComponents) + { + return entities.SelectEntity(selectWithComponents, a => a); + } + + /// + /// Selects an entity from the given list, filtering on entities with + /// the given components. If the entity doesn't match, it is passed as it. + /// + /// The entities to parse. + /// + /// The transformation function for the entity + /// and selected components. If this returns null, then the entity will be filtered + /// out. + /// + /// The type of the first component. + /// The type of the second component. + /// An enumeration of transformed entities. + public static IEnumerable ForEntity( + this IEnumerable entities, + Func selectWithComponents) + { + return entities.SelectEntity(selectWithComponents, a => a); + } + + /// + /// Selects an entity from the given list, filtering on entities with + /// the given components. If the entity doesn't match, it is passed as it. + /// + /// The entities to parse. + /// + /// The transformation function for the entity + /// and selected components. If this returns null, then the entity will be filtered + /// out. + /// + /// The type of the first component. + /// The type of the second component. + /// The type of the third component. + /// An enumeration of transformed entities. + public static IEnumerable ForEntity( + this IEnumerable entities, + Func selectWithComponents) + { + return entities.SelectEntity(selectWithComponents, a => a); + } + + /// + /// Selects an entity from the given list, filtering on entities with + /// the given components. If the entity doesn't match, it is passed as it. + /// + /// The entities to parse. + /// + /// The transformation function for the entity + /// and selected components. If this returns null, then the entity will be filtered + /// out. + /// + /// The type of the first component. + /// The type of the second component. + /// The type of the third component. + /// The type of the third component. + /// An enumeration of transformed entities. + public static IEnumerable ForEntity( + this IEnumerable entities, + Func selectWithComponents) + { + return entities.SelectEntity( + selectWithComponents, + a => a); + } + } +} diff --git a/src/Gallium/Gallium.csproj b/src/Gallium/Gallium.csproj index 41c1f28..d3bb014 100644 --- a/src/Gallium/Gallium.csproj +++ b/src/Gallium/Gallium.csproj @@ -1,7 +1,7 @@ - net5.0 + net6.0 enable diff --git a/src/Gallium/SelectEntityExtensions.cs b/src/Gallium/SelectEntityExtensions.cs new file mode 100644 index 0000000..624181d --- /dev/null +++ b/src/Gallium/SelectEntityExtensions.cs @@ -0,0 +1,171 @@ +using System; +using System.Collections.Generic; + +namespace Gallium +{ + public static class SelectEntityExtensions + { + /// + /// Selects an entity from the given list, filtering on entities with + /// the given components. + /// + /// The entities to parse. + /// + /// The transformation function for the entity + /// and selected components. If this returns null, then the entity will be filtered + /// out. + /// + /// + /// The optional transformation function for + /// entities that do not have all the components. If this is null or returns null, + /// then the entity will not be included. + /// + /// The type of the first component. + /// An enumeration of transformed entities. + public static IEnumerable SelectEntity( + this IEnumerable entities, + Func selectWithComponents, + Func? selectWithoutComponents = null) + { + foreach (Entity entity in entities) + { + Entity? result = entity.TryGet(out T1 value1) + ? selectWithComponents?.Invoke(entity, value1) + : selectWithoutComponents?.Invoke(entity); + + if (result != null) + { + yield return result; + } + } + } + + /// + /// Selects an entity from the given list, filtering on entities with + /// the given components. + /// + /// The entities to parse. + /// + /// The transformation function for the entity + /// and selected components. If this returns null, then the entity will be filtered + /// out. + /// + /// + /// The optional transformation function for + /// entities that do not have all the components. If this is null or returns null, + /// then the entity will not be included. + /// + /// The type of the first component. + /// The type of the second component. + /// An enumeration of transformed entities. + public static IEnumerable SelectEntity( + this IEnumerable entities, + Func selectWithComponents, + Func? selectWithoutComponents = null) + { + foreach (Entity entity in entities) + { + Entity? result = + entity.TryGet(out T1 value1) && entity.TryGet(out T2 value2) + ? selectWithComponents?.Invoke(entity, value1, value2) + : selectWithoutComponents?.Invoke(entity); + + if (result != null) + { + yield return result; + } + } + } + + /// + /// Selects an entity from the given list, filtering on entities with + /// the given components. + /// + /// The entities to parse. + /// + /// The transformation function for the entity + /// and selected components. If this returns null, then the entity will be filtered + /// out. + /// + /// + /// The optional transformation function for + /// entities that do not have all the components. If this is null or returns null, + /// then the entity will not be included. + /// + /// The type of the first component. + /// The type of the second component. + /// The type of the third component. + /// An enumeration of transformed entities. + public static IEnumerable SelectEntity( + this IEnumerable entities, + Func selectWithComponents, + Func? selectWithoutComponents = null) + { + foreach (Entity entity in entities) + { + Entity? result = + entity.TryGet(out T1 value1) + && entity.TryGet(out T2 value2) + && entity.TryGet(out T3 value3) + ? selectWithComponents?.Invoke( + entity, + value1, + value2, + value3) + : selectWithoutComponents?.Invoke(entity); + + if (result != null) + { + yield return result; + } + } + } + + /// + /// Selects an entity from the given list, filtering on entities with + /// the given components. + /// + /// The entities to parse. + /// + /// The transformation function for the entity + /// and selected components. If this returns null, then the entity will be filtered + /// out. + /// + /// + /// The optional transformation function for + /// entities that do not have all the components. If this is null or returns null, + /// then the entity will not be included. + /// + /// The type of the first component. + /// The type of the second component. + /// The type of the third component. + /// The type of the third component. + /// An enumeration of transformed entities. + public static IEnumerable SelectEntity( + this IEnumerable entities, + Func selectWithComponents, + Func? selectWithoutComponents = null) + { + foreach (Entity entity in entities) + { + Entity? result = + entity.TryGet(out T1 value1) + && entity.TryGet(out T2 value2) + && entity.TryGet(out T3 value3) + && entity.TryGet(out T4 value4) + ? selectWithComponents?.Invoke( + entity, + value1, + value2, + value3, + value4) + : selectWithoutComponents?.Invoke(entity); + + if (result != null) + { + yield return result; + } + } + } + } +} diff --git a/src/Gallium/WhereAllComponentsExtensions.cs b/src/Gallium/WhereAllComponentsExtensions.cs new file mode 100644 index 0000000..5d642c9 --- /dev/null +++ b/src/Gallium/WhereAllComponentsExtensions.cs @@ -0,0 +1,34 @@ +using System.Collections.Generic; +using System.Linq; + +namespace Gallium +{ + public static class WhereAllComponentsExtensions + { + public static IEnumerable WhereAllComponents( + this IEnumerable entities) + { + return entities.Where(x => x.Has()); + } + + public static IEnumerable WhereAllComponents( + this IEnumerable entities) + { + return entities.Where(x => x.Has() && x.Has()); + } + + public static IEnumerable WhereAllComponents( + this IEnumerable entities) + { + return entities.Where( + x => x.Has() && x.Has() && x.Has()); + } + + public static IEnumerable WhereAllComponents( + this IEnumerable entities) + { + return entities.Where( + x => x.Has() && x.Has() && x.Has() && x.Has()); + } + } +} diff --git a/src/Gallium/WhereComponentsExtensions.cs b/src/Gallium/WhereComponentsExtensions.cs new file mode 100644 index 0000000..d7f1e98 --- /dev/null +++ b/src/Gallium/WhereComponentsExtensions.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Gallium +{ + public static class WhereComponentsExtensions + { + public static IEnumerable WhereComponents( + this IEnumerable entities, + Func include) + { + return entities.Where(x => x.Has() && include(x, x.Get())); + } + + public static IEnumerable WhereComponents( + this IEnumerable entities, + Func include) + { + return entities.Where( + x => x.Has() + && x.Has() + && include(x, x.Get(), x.Get())); + } + + public static IEnumerable WhereComponents( + this IEnumerable entities, + Func include) + { + return entities.Where( + x => x.Has() + && x.Has() + && x.Has() + && include(x, x.Get(), x.Get(), x.Get())); + } + + public static IEnumerable WhereComponents( + this IEnumerable entities, + Func include) + { + return entities.Where( + x => x.Has() + && x.Has() + && x.Has() + && x.Has() + && include( + x, + x.Get(), + x.Get(), + x.Get(), + x.Get())); + } + } +} diff --git a/src/Gallium/WhereNotAllComponentExtensions.cs b/src/Gallium/WhereNotAllComponentExtensions.cs new file mode 100644 index 0000000..b9e4fe5 --- /dev/null +++ b/src/Gallium/WhereNotAllComponentExtensions.cs @@ -0,0 +1,44 @@ +using System.Collections.Generic; +using System.Linq; + +namespace Gallium +{ + public static class WhereNotAllComponentExtensions + { + public static IEnumerable WhereNotComponent( + this IEnumerable entities) + { + return entities.Where(x => !x.Has()); + } + + public static IEnumerable WhereNotAllComponents( + this IEnumerable entities) + { + return entities.Where(x => !x.Has()); + } + + + public static IEnumerable WhereNotAllComponents( + this IEnumerable entities) + { + return entities.Where(x => !x.HasAll()); + } + + public static IEnumerable WhereNotAllComponents( + this IEnumerable entities) + { + return entities.Where( + x => !x.HasAll()); + } + + public static IEnumerable WhereNotAllComponents( + this IEnumerable entities) + { + return entities.Where( + x => !x.Has() + || !x.Has() + || !x.Has() + || !x.Has()); + } + } +}