Skip to content

Commit 79a9eee

Browse files
committed
Rename ConditionalCriterionProjectionPair to ConditionalProjectionCase
1 parent 6fde9ca commit 79a9eee

File tree

6 files changed

+64
-64
lines changed

6 files changed

+64
-64
lines changed

src/NHibernate.Test/Async/Criteria/ConditionalProjectionTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public async Task UsingMultiConditionalsAsync()
7171
var criterionProjections =
7272
orderOfNames
7373
.Select(
74-
x => new ConditionalCriterionProjectionPair(
74+
x => new ConditionalProjectionCase(
7575
Restrictions.Eq(nameof(Student.Name), x.Item1),
7676
Projections.Constant(x.Item2)))
7777
.ToArray();

src/NHibernate.Test/Criteria/ConditionalProjectionTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void UsingMultiConditionals()
6060
var criterionProjections =
6161
orderOfNames
6262
.Select(
63-
x => new ConditionalCriterionProjectionPair(
63+
x => new ConditionalProjectionCase(
6464
Restrictions.Eq(nameof(Student.Name), x.Item1),
6565
Projections.Constant(x.Item2)))
6666
.ToArray();

src/NHibernate/Criterion/ConditionalCriterionProjectionPair.cs

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
namespace NHibernate.Criterion
2+
{
3+
/// <summary>
4+
/// Defines a pair of <see cref="ConditionalProjectionCase.Criterion"/> and <see cref="ConditionalProjectionCase.Projection"/>.
5+
/// </summary>
6+
public class ConditionalProjectionCase
7+
{
8+
/// <summary>
9+
/// Initializes a new instance of the <see cref="ConditionalProjectionCase"/> class.
10+
/// </summary>
11+
/// <param name="criterion">The <see cref="ConditionalProjectionCase.Criterion"/>.</param>
12+
/// <param name="projection">The <see cref="ConditionalProjectionCase.Projection"/>.</param>
13+
public ConditionalProjectionCase(ICriterion criterion, IProjection projection)
14+
{
15+
Criterion = criterion;
16+
Projection = projection;
17+
}
18+
19+
/// <summary>
20+
/// Gets the <see cref="ICriterion"/>.
21+
/// </summary>
22+
public ICriterion Criterion { get; }
23+
24+
/// <summary>
25+
/// Gets the <see cref="IProjection"/>.
26+
/// </summary>
27+
public IProjection Projection { get; }
28+
}
29+
}

src/NHibernate/Criterion/ConditionalsProjection.cs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,43 @@
88
namespace NHibernate.Criterion
99
{
1010
/// <summary>
11-
/// Defines a "switch" projection which supports multiple "cases" ("when/then's") using <see cref="ConditionalCriterionProjectionPair"/>.
11+
/// Defines a "switch" projection which supports multiple "cases" ("when/then's") using <see cref="ConditionalProjectionCase"/>.
1212
/// Can be used in Orderby for example.
1313
/// </summary>
1414
/// <seealso cref="SimpleProjection" />
15-
/// <seealso cref="ConditionalCriterionProjectionPair" />
15+
/// <seealso cref="ConditionalProjectionCase" />
1616
[Serializable]
1717
public sealed class ConditionalsProjection : SimpleProjection
1818
{
19-
private readonly ConditionalCriterionProjectionPair[] criterionProjections;
19+
private readonly ConditionalProjectionCase[] _cases;
2020
private readonly IProjection elseProjection;
2121

2222
/// <summary>
2323
/// Initializes a new instance of the <see cref="ConditionalsProjection"/> class.
2424
/// </summary>
25-
/// <param name="conditionalProjections">The <see cref="ConditionalCriterionProjectionPair"/>s containg your <see cref="ICriterion"/> and <see cref="IProjection"/> pairs.</param>
25+
/// <param name="cases">The <see cref="ConditionalProjectionCase"/>s containg your <see cref="ICriterion"/> and <see cref="IProjection"/> pairs.</param>
2626
/// <param name="elseProjection">The else <see cref="IProjection"/>.</param>
27-
/// <exception cref="ArgumentNullException"><paramref name="conditionalProjections"/> is null.</exception>
27+
/// <exception cref="ArgumentNullException"><paramref name="cases"/> is null.</exception>
2828
/// <exception cref="ArgumentNullException"><paramref name="elseProjection"/> is null.</exception>
29-
/// <exception cref="ArgumentOutOfRangeException"><paramref name="conditionalProjections"/> should not be empty.</exception>
30-
public ConditionalsProjection(ConditionalCriterionProjectionPair[] conditionalProjections, IProjection elseProjection)
29+
/// <exception cref="ArgumentOutOfRangeException"><paramref name="cases"/> should not be empty.</exception>
30+
public ConditionalsProjection(ConditionalProjectionCase[] cases, IProjection elseProjection)
3131
{
3232
if (elseProjection is null)
3333
{
3434
throw new ArgumentNullException(nameof(elseProjection));
3535
}
3636

37-
if (conditionalProjections is null)
37+
if (cases is null)
3838
{
39-
throw new ArgumentNullException(nameof(conditionalProjections));
39+
throw new ArgumentNullException(nameof(cases));
4040
}
4141

42-
if (conditionalProjections.Length == 0)
42+
if (cases.Length == 0)
4343
{
44-
throw new ArgumentOutOfRangeException(nameof(this.criterionProjections), "Array should not be empty.");
44+
throw new ArgumentOutOfRangeException(nameof(cases), "Array should not be empty.");
4545
}
4646

47-
this.criterionProjections = conditionalProjections.ToArray();
47+
_cases = cases;
4848
this.elseProjection = elseProjection;
4949
}
5050

@@ -55,28 +55,28 @@ public override bool IsAggregate
5555
if (this.elseProjection.IsAggregate)
5656
return true;
5757

58-
for (int i = 0; i < this.criterionProjections.Length; i++)
58+
for (int i = 0; i < _cases.Length; i++)
5959
{
60-
if (this.CalcIsAggregate(this.criterionProjections[i]))
60+
if (this.CalcIsAggregate(_cases[i]))
6161
return true;
6262
}
6363

6464
return false;
6565
}
6666
}
6767

68-
public override bool IsGrouped => this.elseProjection.IsGrouped || this.CalcIsGrouped(this.criterionProjections);
68+
public override bool IsGrouped => this.elseProjection.IsGrouped || this.CalcIsGrouped(_cases);
6969

7070
public override SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery)
7171
{
72-
object[] parts = new object[5 + (this.criterionProjections.Length * 4)];
72+
object[] parts = new object[5 + (_cases.Length * 4)];
7373
var index = 0;
7474

7575
parts[index++] = "(case";
7676

77-
for (int i = 0; i < criterionProjections.Length; i++)
77+
for (int i = 0; i < _cases.Length; i++)
7878
{
79-
ConditionalCriterionProjectionPair conditional = this.criterionProjections[i];
79+
ConditionalProjectionCase conditional = _cases[i];
8080
parts[index++] = " when ";
8181
parts[index++] = conditional.Criterion.ToSqlString(criteria, criteriaQuery);
8282
parts[index++] = " then ";
@@ -96,9 +96,9 @@ public override IType[] GetTypes(ICriteria criteria, ICriteriaQuery criteriaQuer
9696
{
9797
var elseTypes = this.elseProjection.GetTypes(criteria, criteriaQuery);
9898

99-
for (int i = 0; i < this.criterionProjections.Length; i++)
99+
for (int i = 0; i < _cases.Length; i++)
100100
{
101-
var subsequentTypes = this.criterionProjections[i].Projection.GetTypes(criteria, criteriaQuery);
101+
var subsequentTypes = _cases[i].Projection.GetTypes(criteria, criteriaQuery);
102102

103103
this.AssertAreEqualTypes(elseTypes, subsequentTypes, i.ToString());
104104
}
@@ -110,10 +110,10 @@ public override TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery c
110110
{
111111
List<TypedValue> typedValues = new List<TypedValue>();
112112

113-
for (int i = 0; i < this.criterionProjections.Length; i++)
113+
for (int i = 0; i < _cases.Length; i++)
114114
{
115-
typedValues.AddRange(this.criterionProjections[i].Criterion.GetTypedValues(criteria, criteriaQuery));
116-
typedValues.AddRange(this.criterionProjections[i].Projection.GetTypedValues(criteria, criteriaQuery));
115+
typedValues.AddRange(_cases[i].Criterion.GetTypedValues(criteria, criteriaQuery));
116+
typedValues.AddRange(_cases[i].Projection.GetTypedValues(criteria, criteriaQuery));
117117
}
118118

119119
typedValues.AddRange(this.elseProjection.GetTypedValues(criteria, criteriaQuery));
@@ -125,7 +125,7 @@ public override SqlString ToGroupSqlString(ICriteria criteria, ICriteriaQuery cr
125125
{
126126
SqlStringBuilder sqlBuilder = new SqlStringBuilder();
127127

128-
this.AddToGroupedSql(sqlBuilder, this.criterionProjections, criteria, criteriaQuery);
128+
this.AddToGroupedSql(sqlBuilder, _cases, criteria, criteriaQuery);
129129
this.AddToGroupedSql(sqlBuilder, this.elseProjection, criteria, criteriaQuery);
130130

131131
// ??
@@ -137,7 +137,7 @@ public override SqlString ToGroupSqlString(ICriteria criteria, ICriteriaQuery cr
137137
return sqlBuilder.ToSqlString();
138138
}
139139

140-
private bool CalcIsGrouped(IList<ConditionalCriterionProjectionPair> criterionProjections)
140+
private bool CalcIsGrouped(IList<ConditionalProjectionCase> criterionProjections)
141141
{
142142
for (int i = 0; i < criterionProjections.Count; i++)
143143
{
@@ -187,7 +187,7 @@ private bool CalcIsGrouped(IProjection[] projections)
187187
return false;
188188
}
189189

190-
private bool CalcIsAggregate(ConditionalCriterionProjectionPair criterionProjection)
190+
private bool CalcIsAggregate(ConditionalProjectionCase criterionProjection)
191191
{
192192
if (criterionProjection.Projection.IsAggregate)
193193
return true;
@@ -202,15 +202,15 @@ private bool CalcIsAggregate(ConditionalCriterionProjectionPair criterionProject
202202
return false;
203203
}
204204

205-
private void AddToGroupedSql(SqlStringBuilder sqlBuilder, ConditionalCriterionProjectionPair[] criterionProjections, ICriteria criteria, ICriteriaQuery criteriaQuery)
205+
private void AddToGroupedSql(SqlStringBuilder sqlBuilder, ConditionalProjectionCase[] criterionProjections, ICriteria criteria, ICriteriaQuery criteriaQuery)
206206
{
207207
for (int i = 0; i < criterionProjections.Length; i++)
208208
{
209209
this.AddToGroupedSql(sqlBuilder, criterionProjections[i], criteria, criteriaQuery);
210210
}
211211
}
212212

213-
private void AddToGroupedSql(SqlStringBuilder sqlBuilder, ConditionalCriterionProjectionPair criterionProjection, ICriteria criteria, ICriteriaQuery criteriaQuery)
213+
private void AddToGroupedSql(SqlStringBuilder sqlBuilder, ConditionalProjectionCase criterionProjection, ICriteria criteria, ICriteriaQuery criteriaQuery)
214214
{
215215
this.AddToGroupedSql(sqlBuilder, criterionProjection.Criterion, criteria, criteriaQuery);
216216
this.AddToGroupedSql(sqlBuilder, criterionProjection.Projection, criteria, criteriaQuery);

src/NHibernate/Criterion/Projections.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,15 +357,15 @@ public static IProjection Conditional(ICriterion criterion, IProjection whenTrue
357357
}
358358

359359
/// <summary>
360-
/// Conditionally returns one of the <see cref="ConditionalCriterionProjectionPair.Projection"/>s depending on the <see cref="ConditionalCriterionProjectionPair.Criterion"/>s of <paramref name="criterionProjections"/> or the <paramref name="elseProjection"/>.
360+
/// Conditionally returns one of the <see cref="ConditionalProjectionCase.Projection"/>s depending on the <see cref="ConditionalProjectionCase.Criterion"/>s of <paramref name="cases"/> or the <paramref name="elseProjection"/>.
361361
/// This produces an switch-case expression with multiple when-then parts.
362362
/// </summary>
363-
/// <param name="criterionProjections">The <see cref="ConditionalCriterionProjectionPair"/>s which contain your <see cref="ICriterion"/>s and <see cref="IProjection"/>s.</param>
363+
/// <param name="cases">The <see cref="ConditionalProjectionCase"/>s which contain your <see cref="ICriterion"/>s and <see cref="IProjection"/>s.</param>
364364
/// <param name="elseProjection">The else <see cref="IProjection"/>.</param>
365-
/// <returns>A <see cref="IProjection"/> for a switch-expression with multiple <see cref="ICriterion">Criterions</see> ("when") <see cref="IProjection">Projections</see> ("then").</returns>
366-
public static IProjection Conditionals(ConditionalCriterionProjectionPair[] criterionProjections, IProjection elseProjection)
365+
/// <returns>A <see cref="IProjection"/> for a switch-expression with multiple <see cref="ICriterion">Criteria</see> ("when") <see cref="IProjection">Projections</see> ("then").</returns>
366+
public static IProjection Conditionals(ConditionalProjectionCase[] cases, IProjection elseProjection)
367367
{
368-
return new ConditionalsProjection(criterionProjections, elseProjection);
368+
return new ConditionalsProjection(cases, elseProjection);
369369
}
370370

371371
public static IProjection SubQuery(DetachedCriteria detachedCriteria)

0 commit comments

Comments
 (0)