forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRestrictionsExtensions.cs
152 lines (135 loc) · 6.5 KB
/
RestrictionsExtensions.cs
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
using System;
using System.Collections;
using System.Linq.Expressions;
using NHibernate.Impl;
namespace NHibernate.Criterion
{
public static class RestrictionExtensions
{
/// <summary>
/// Apply a "like" restriction in a QueryOver expression
/// Note: throws an exception outside of a QueryOver expression
/// </summary>
public static bool IsLike(this string projection, string comparison)
{
throw QueryOver.GetDirectUsageException();
}
/// <summary>
/// Apply a "like" restriction in a QueryOver expression
/// Note: throws an exception outside of a QueryOver expression
/// </summary>
public static bool IsLike(this string projection, string comparison, MatchMode matchMode)
{
throw QueryOver.GetDirectUsageException();
}
/// <summary>
/// Apply a "like" restriction in a QueryOver expression
/// Note: throws an exception outside of a QueryOver expression
/// </summary>
public static bool IsLike(this string projection, string comparison, MatchMode matchMode, char? escapeChar)
{
throw QueryOver.GetDirectUsageException();
}
/// <summary>
/// Apply a "like" restriction in a QueryOver expression
/// Note: throws an exception outside of a QueryOver expression
/// </summary>
public static bool IsInsensitiveLike(this string projection, string comparison)
{
throw QueryOver.GetDirectUsageException();
}
/// <summary>
/// Apply a "like" restriction in a QueryOver expression
/// Note: throws an exception outside of a QueryOver expression
/// </summary>
public static bool IsInsensitiveLike(this string projection, string comparison, MatchMode matchMode)
{
throw QueryOver.GetDirectUsageException();
}
/// <summary>
/// Apply an "in" constraint to the named property
/// Note: throws an exception outside of a QueryOver expression
/// </summary>
public static bool IsIn(this object projection, object[] values)
{
throw QueryOver.GetDirectUsageException();
}
/// <summary>
/// Apply an "in" constraint to the named property
/// Note: throws an exception outside of a QueryOver expression
/// </summary>
public static bool IsIn(this object projection, ICollection values)
{
throw QueryOver.GetDirectUsageException();
}
/// <summary>
/// Apply a "between" constraint to the named property
/// Note: throws an exception outside of a QueryOver expression
/// </summary>
public static RestrictionBetweenBuilder IsBetween(this object projection, object lo)
{
throw QueryOver.GetDirectUsageException();
}
public class RestrictionBetweenBuilder
{
public bool And(object hi)
{
throw QueryOver.GetDirectUsageException();
}
}
public static ICriterion ProcessIsLike(MethodCallExpression methodCallExpression)
{
ExpressionProcessor.ProjectionInfo projection = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]);
object value = ExpressionProcessor.FindValue(methodCallExpression.Arguments[1]);
return projection.CreateCriterion(Restrictions.Like, Restrictions.Like, value);
}
public static ICriterion ProcessIsLikeMatchMode(MethodCallExpression methodCallExpression)
{
ExpressionProcessor.ProjectionInfo projection = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]);
string value = (string)ExpressionProcessor.FindValue(methodCallExpression.Arguments[1]);
MatchMode matchMode = (MatchMode)ExpressionProcessor.FindValue(methodCallExpression.Arguments[2]);
return projection.Create<ICriterion>(s => Restrictions.Like(s, value, matchMode), p => Restrictions.Like(p, value, matchMode));
}
public static ICriterion ProcessIsLikeMatchModeEscapeChar(MethodCallExpression methodCallExpression)
{
string property = ExpressionProcessor.FindMemberExpression(methodCallExpression.Arguments[0]);
string value = (string)ExpressionProcessor.FindValue(methodCallExpression.Arguments[1]);
MatchMode matchMode = (MatchMode)ExpressionProcessor.FindValue(methodCallExpression.Arguments[2]);
char? escapeChar = (char?)ExpressionProcessor.FindValue(methodCallExpression.Arguments[3]);
return Restrictions.Like(property, value, matchMode, escapeChar);
}
public static ICriterion ProcessIsInsensitiveLike(MethodCallExpression methodCallExpression)
{
ExpressionProcessor.ProjectionInfo projection = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]);
object value = ExpressionProcessor.FindValue(methodCallExpression.Arguments[1]);
return projection.CreateCriterion(Restrictions.InsensitiveLike, Restrictions.InsensitiveLike, value);
}
public static ICriterion ProcessIsInsensitiveLikeMatchMode(MethodCallExpression methodCallExpression)
{
ExpressionProcessor.ProjectionInfo projection = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]);
string value = (string)ExpressionProcessor.FindValue(methodCallExpression.Arguments[1]);
MatchMode matchMode = (MatchMode)ExpressionProcessor.FindValue(methodCallExpression.Arguments[2]);
return projection.Create<ICriterion>(s => Restrictions.InsensitiveLike(s, value, matchMode), p => Restrictions.InsensitiveLike(p, value, matchMode));
}
public static ICriterion ProcessIsInArray(MethodCallExpression methodCallExpression)
{
ExpressionProcessor.ProjectionInfo projection = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]);
object[] values = (object[])ExpressionProcessor.FindValue(methodCallExpression.Arguments[1]);
return projection.Create<ICriterion>(s => Restrictions.In(s, values), p => Restrictions.In(p, values));
}
public static ICriterion ProcessIsInCollection(MethodCallExpression methodCallExpression)
{
ExpressionProcessor.ProjectionInfo projection = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]);
var values = (ICollection)ExpressionProcessor.FindValue(methodCallExpression.Arguments[1]);
return projection.Create<ICriterion>(s => Restrictions.In(s, values), p => Restrictions.In(p, values));
}
public static ICriterion ProcessIsBetween(MethodCallExpression methodCallExpression)
{
MethodCallExpression betweenFunction = (MethodCallExpression)methodCallExpression.Object;
ExpressionProcessor.ProjectionInfo projection = ExpressionProcessor.FindMemberProjection(betweenFunction.Arguments[0]);
object lo = ExpressionProcessor.FindValue(betweenFunction.Arguments[1]);
object hi = ExpressionProcessor.FindValue(methodCallExpression.Arguments[0]);
return projection.Create<ICriterion>(s => Restrictions.Between(s, lo, hi), p => Restrictions.Between(p, lo, hi));
}
}
}