forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNestedQueryEnumerable.cs
More file actions
62 lines (52 loc) · 2.09 KB
/
Copy pathNestedQueryEnumerable.cs
File metadata and controls
62 lines (52 loc) · 2.09 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
61
62
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System.Collections;
using System.Collections.Generic;
namespace UnityEditor.Search
{
class NestedQueryEnumerable<T> : IQueryEnumerable<T>
{
IEnumerable<T> m_NestedQueryEnumerable;
public bool fastYielding { get; }
public NestedQueryEnumerable(IEnumerable<T> nestedQueryEnumerable, bool fastYielding)
{
m_NestedQueryEnumerable = nestedQueryEnumerable;
this.fastYielding = fastYielding;
}
public void SetPayload(IEnumerable<T> payload)
{}
public IEnumerator<T> GetEnumerator()
{
return m_NestedQueryEnumerable.GetEnumerator();
}
public IEnumerator<T> FastYieldingEnumerator()
{
return GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
[EnumerableCreator(QueryNodeType.NestedQuery)]
class NestedQueryEnumerableFactory : IQueryEnumerableFactory
{
public IQueryEnumerable<T> Create<T>(IQueryNode root, QueryEngine<T> engine, ICollection<QueryError> errors, bool fastYielding)
{
var nestedQueryNode = root as NestedQueryNode;
var nestedQueryHandler = nestedQueryNode?.nestedQueryHandler as NestedQueryHandler<T>;
if (nestedQueryHandler == null)
{
errors.Add(new QueryError(root.token.position, root.token.length, "There is no handler set for nested queries."));
return null;
}
var nestedEnumerable = nestedQueryHandler.handler(nestedQueryNode.identifier, nestedQueryNode.associatedFilter);
if (nestedEnumerable == null)
{
errors.Add(new QueryError(root.token.position, root.token.length, "Could not create enumerable from nested query handler."));
}
return new NestedQueryEnumerable<T>(nestedEnumerable, fastYielding);
}
}
}