-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathEntityExtensions.cs
More file actions
69 lines (64 loc) · 2.15 KB
/
EntityExtensions.cs
File metadata and controls
69 lines (64 loc) · 2.15 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
#if NET10_0_OR_GREATER
namespace EntityFrameworkCore.Projectables.FunctionalTests.ExtensionMembers
{
public static class EntityExtensions
{
extension(Entity e)
{
/// <summary>
/// Extension member property that doubles the entity's ID.
/// </summary>
[Projectable]
public int DoubleId => e.Id * 2;
/// <summary>
/// Extension member method that triples the entity's ID.
/// </summary>
[Projectable]
public int TripleId() => e.Id * 3;
/// <summary>
/// Extension member method that multiplies the entity's ID by a factor.
/// </summary>
[Projectable]
public int Multiply(int factor) => e.Id * factor;
}
}
/// <summary>
/// Extension on a closed generic receiver type: <c>extension(GenericWrapper<Entity> w)</c>.
/// Tests the fix for the bug where <c>global::</c> inside generic type arguments caused a
/// name mismatch between the generated class and the runtime resolver.
/// </summary>
public static class ClosedGenericWrapperExtensions
{
extension(GenericWrapper<Entity> w)
{
[Projectable]
public int DoubleId() => w.Id * 2;
}
}
/// <summary>
/// Extension on an open generic receiver type: <c>extension<T>(GenericWrapper<T> w)</c>.
/// The block-level type parameter <c>T</c> becomes a method-level type parameter on the
/// generated <c>Expression<T>()</c> factory, resolved at runtime via generic method
/// reflection.
/// </summary>
public static class OpenGenericWrapperExtensions
{
extension<T>(GenericWrapper<T> w) where T : class
{
[Projectable]
public int TripleId() => w.Id * 3;
}
}
public static class IntExtensions
{
extension(int i)
{
/// <summary>
/// Extension member property that squares an integer.
/// </summary>
[Projectable]
public int SquaredMember => i * i;
}
}
}
#endif