forked from actionk/Morpeh.Queries
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueryBuilder.cs
More file actions
60 lines (49 loc) · 1.95 KB
/
QueryBuilder.cs
File metadata and controls
60 lines (49 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System.Reflection;
namespace Scellecs.Morpeh
{
public class QueryBuilder
{
private static readonly MethodInfo FILTER_WITH_METHOD_INFO = typeof(FilterExtensions).GetMethod("With");
private static readonly MethodInfo FILTER_WITHOUT_METHOD_INFO = typeof(FilterExtensions).GetMethod("Without");
private readonly QuerySystem m_querySystem;
internal Filter filter;
public World World => m_querySystem.World;
public QuerySystem System => m_querySystem;
internal bool skipValidationEnabled;
internal bool ignoreGlobalsEnabled;
public QueryBuilder(QuerySystem querySystem)
{
m_querySystem = querySystem;
filter = querySystem.World.Filter;
}
public Filter Build()
{
if (!ignoreGlobalsEnabled)
{
if (QueryBuilderGlobals.TYPES_TO_REQUIRE.length > 0)
{
for (var i = 0; i < QueryBuilderGlobals.TYPES_TO_REQUIRE.length; i++)
filter = (Filter)FILTER_WITH_METHOD_INFO.MakeGenericMethod(QueryBuilderGlobals.TYPES_TO_REQUIRE.data[i]).Invoke(filter, new object[] { filter });
}
if (QueryBuilderGlobals.TYPES_TO_IGNORE.length > 0)
{
for (var i = 0; i < QueryBuilderGlobals.TYPES_TO_IGNORE.length; i++)
filter = (Filter)FILTER_WITHOUT_METHOD_INFO.MakeGenericMethod(QueryBuilderGlobals.TYPES_TO_IGNORE.data[i]).Invoke(filter, new object[] { filter });
}
}
return filter;
}
#region Parameters
public QueryBuilder SkipValidation(bool skipValidation)
{
skipValidationEnabled = skipValidation;
return this;
}
public QueryBuilder IgnoreGlobals(bool ignoreGlobals)
{
ignoreGlobalsEnabled = ignoreGlobals;
return this;
}
#endregion
}
}