forked from dotnet/efcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuerySourceScope.cs
More file actions
70 lines (61 loc) · 2.45 KB
/
Copy pathQuerySourceScope.cs
File metadata and controls
70 lines (61 loc) · 2.45 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
63
64
65
66
67
68
69
70
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using JetBrains.Annotations;
using Remotion.Linq.Clauses;
namespace Microsoft.Data.Entity.Query
{
public abstract class QuerySourceScope
{
private static readonly MethodInfo _createMethodInfo
= typeof(QuerySourceScope).GetTypeInfo()
.GetDeclaredMethods("Create").FirstOrDefault(m => m.IsStatic && !m.IsPublic);
public static readonly MethodInfo GetResultMethodInfo
= typeof(QuerySourceScope).GetTypeInfo()
.GetDeclaredMethods("GetResult").FirstOrDefault(m => !m.IsStatic && !m.IsPublic);
public static Expression Create(
[NotNull] IQuerySource querySource,
[NotNull] Expression result,
[NotNull] Expression parentScope)
{
return Expression.Call(
_createMethodInfo.MakeGenericMethod(result.Type),
Expression.Constant(querySource),
result,
parentScope);
}
public static Expression GetResult(
[NotNull] Expression querySourceScope,
[NotNull] IQuerySource querySource,
[NotNull] Type resultType)
{
return Expression.Call(
querySourceScope,
GetResultMethodInfo.MakeGenericMethod(resultType),
Expression.Constant(querySource));
}
private readonly QuerySourceScope _parentScope;
private readonly IQuerySource _querySource;
protected QuerySourceScope(IQuerySource querySource, QuerySourceScope parentScope)
{
_querySource = querySource;
_parentScope = parentScope;
}
[UsedImplicitly]
private static QuerySourceScope<TResult> Create<TResult>(
IQuerySource querySource, TResult result, QuerySourceScope parentScope)
{
return new QuerySourceScope<TResult>(querySource, result, parentScope);
}
[UsedImplicitly]
private TResult GetResult<TResult>(IQuerySource querySource)
{
return _querySource == querySource
? ((QuerySourceScope<TResult>)this)._result
: _parentScope.GetResult<TResult>(querySource);
}
}
}