Skip to content

Commit 2f94c54

Browse files
author
Robert Anderson
committed
Code cleanup for detecting features on OData entities.
1 parent 50c126e commit 2f94c54

14 files changed

+98
-125
lines changed

Templates/CSharp/Requests/EntityCollectionRequest.cs.tt

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,7 @@ var innerEntityType = innerEntity.Name.ToCheckedCase();
88
var collectionRequest = string.Concat(prop.Class.Name.ToCheckedCase(), prop.Name.ToCheckedCase(), "CollectionRequest");
99
var collectionResponse = string.Concat(prop.Class.Name.ToCheckedCase(), prop.Name.ToCheckedCase(), "CollectionResponse");
1010
var collectionPage = string.Concat(prop.Class.Name.ToCheckedCase(), prop.Name.ToCheckedCase(), "CollectionPage");
11-
12-
var projection = host.CurrentType.Projection;
13-
var canExpand = projection.SupportsExpand();
14-
var canSelect = projection.BooleanValueOf("Selectable") != false;
15-
var canFilter = projection.BooleanValueOf("Filterable") != false;
16-
var canUseTop = projection.BooleanValueOf("TopSupported") != false;
17-
var canSkip = projection.BooleanValueOf("SkipSupported") != false;
18-
var canSort = projection.BooleanValueOf("Sortable") != false;
19-
11+
var features = host.CurrentType.GetFeatures();
2012
#>
2113

2214
namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
@@ -75,7 +67,7 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
7567
return null;
7668
}
7769

78-
<# if (canExpand) { #>
70+
<# if (features.CanExpand) { #>
7971
/// <summary>
8072
/// Adds the specified expand value to the request.
8173
/// </summary>
@@ -88,7 +80,7 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
8880
}
8981

9082
<# } #>
91-
<# if (canSelect) { #>
83+
<# if (features.CanSelect) { #>
9284
/// <summary>
9385
/// Adds the specified select value to the request.
9486
/// </summary>
@@ -101,7 +93,7 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
10193
}
10294

10395
<# } #>
104-
<# if (canUseTop) { #>
96+
<# if (features.CanUseTop) { #>
10597
/// <summary>
10698
/// Adds the specified top value to the request.
10799
/// </summary>
@@ -114,7 +106,7 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
114106
}
115107

116108
<# } #>
117-
<# if (canFilter) { #>
109+
<# if (features.CanFilter) { #>
118110
/// <summary>
119111
/// Adds the specified filter value to the request.
120112
/// </summary>
@@ -127,7 +119,7 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
127119
}
128120

129121
<# } #>
130-
<# if (canSkip) { #>
122+
<# if (features.CanSkip) { #>
131123
/// <summary>
132124
/// Adds the specified skip value to the request.
133125
/// </summary>
@@ -140,7 +132,7 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
140132
}
141133

142134
<# } #>
143-
<# if (canSort) { #>
135+
<# if (features.CanSort) { #>
144136
/// <summary>
145137
/// Adds the specified orderby value to the request.
146138
/// </summary>

Templates/CSharp/Requests/EntityCollectionWithReferencesRequest.cs.tt

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,7 @@ var propName = prop.Name.ToCheckedCase();
1111
var collectionResponse = string.Concat(prop.Class.Name.ToCheckedCase(), propName , "CollectionWithReferencesResponse");
1212
var collectionPage = string.Concat(prop.Class.Name.ToCheckedCase(), propName , "CollectionWithReferencesPage");
1313

14-
var projection = host.CurrentType.Projection;
15-
var canExpand = projection.SupportsExpand();
16-
var canSelect = projection.BooleanValueOf("Selectable") != false;
17-
var canFilter = projection.BooleanValueOf("Filterable") != false;
18-
var canUseTop = projection.BooleanValueOf("TopSupported") != false;
19-
var canSkip = projection.BooleanValueOf("SkipSupported") != false;
20-
var canSort = projection.BooleanValueOf("Sortable") != false;
21-
14+
var features = host.CurrentType.GetFeatures();
2215
#>
2316

2417
namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
@@ -77,7 +70,7 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
7770
return null;
7871
}
7972

80-
<# if (canExpand) { #>
73+
<# if (features.CanExpand) { #>
8174
/// <summary>
8275
/// Adds the specified expand value to the request.
8376
/// </summary>
@@ -90,7 +83,7 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
9083
}
9184

9285
<# } #>
93-
<# if (canSelect) { #>
86+
<# if (features.CanSelect) { #>
9487
/// <summary>
9588
/// Adds the specified select value to the request.
9689
/// </summary>
@@ -103,7 +96,7 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
10396
}
10497

10598
<# } #>
106-
<# if (canUseTop) { #>
99+
<# if (features.CanUseTop) { #>
107100
/// <summary>
108101
/// Adds the specified top value to the request.
109102
/// </summary>
@@ -116,7 +109,7 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
116109
}
117110

118111
<# } #>
119-
<# if (canFilter) { #>
112+
<# if (features.CanFilter) { #>
120113
/// <summary>
121114
/// Adds the specified filter value to the request.
122115
/// </summary>
@@ -129,7 +122,7 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
129122
}
130123

131124
<# } #>
132-
<# if (canSkip) { #>
125+
<# if (features.CanSkip) { #>
133126
/// <summary>
134127
/// Adds the specified skip value to the request.
135128
/// </summary>
@@ -142,7 +135,7 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
142135
}
143136

144137
<# } #>
145-
<# if (canSort) { #>
138+
<# if (features.CanSort) { #>
146139
/// <summary>
147140
/// Adds the specified orderby value to the request.
148141
/// </summary>

Templates/CSharp/Requests/EntityReferenceRequest.cs.tt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
OdcmClass entity = host.CurrentType.AsOdcmClass();
77
var entityName = this.GetEntityNameString(entity);
88

9-
var projection = host.CurrentType.Projection;
10-
var canDelete = projection.SupportsDelete();
9+
var features = host.CurrentType.GetFeatures();
1110

1211
#>
1312

@@ -21,7 +20,7 @@ namespace <#=this.GetNamespaceName(entity)#>
2120
<#=this.GetEntityReferenceRequestClassDefinition(entity)#>
2221
{
2322
<#=this.GetEntityReferenceRequestConstructor(entity)#>
24-
<# if (canDelete) { #>
23+
<# if (features.CanDelete) { #>
2524

2625
<#=this.GetEntityReferenceDeleteAsyncMethod(entity)#>
2726
<# } #>

Templates/CSharp/Requests/EntityRequest.cs.tt

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@
66
OdcmClass entity = host.CurrentType.AsOdcmClass();
77
var entityName = this.GetEntityNameString(entity);
88

9-
var projection = host.CurrentType.Projection;
10-
var canCreate = projection.SupportsInsert();
11-
var canDelete = projection.SupportsDelete();
12-
var canUpdate = projection.SupportsUpdate();
13-
var canExpand = projection.SupportsExpand();
14-
var canSelect = projection.BooleanValueOf("Selectable") != false;
9+
var features = host.CurrentType.GetFeatures();
1510

1611
#>
1712

@@ -29,14 +24,14 @@ namespace <#=this.GetNamespaceName(entity)#>
2924
<#=this.GetEntityRequestConstructor(entity)#>
3025

3126
<#
32-
if (canCreate)
27+
if (features.CanCreate)
3328
{
3429
Write(" ");
3530
Write(this.GetEntityCreateAsyncMethod(entity));
3631
Write("\n\n");
3732
}
3833

39-
if (canDelete)
34+
if (features.CanDelete)
4035
{
4136
Write(" ");
4237
Write(this.GetEntityDeleteAsyncMethod(entity));
@@ -47,21 +42,21 @@ namespace <#=this.GetNamespaceName(entity)#>
4742
Write(this.GetEntityGetAsyncMethod(entity));
4843
Write("\n\n");
4944

50-
if (canUpdate)
45+
if (features.CanUpdate)
5146
{
5247
Write(" ");
5348
Write(this.GetEntityUpdateAsyncMethod(entity));
5449
Write("\n\n");
5550
}
5651

57-
if (canExpand)
52+
if (features.CanExpand)
5853
{
5954
Write(" ");
6055
Write(this.GetEntityExpandMethod(entity));
6156
Write("\n\n");
6257
}
6358

64-
if (canSelect)
59+
if (features.CanSelect)
6560
{
6661
Write(" ");
6762
Write(this.GetEntitySelectMethod(entity));

Templates/CSharp/Requests/EntityWithReferenceRequest.cs.tt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
OdcmClass entity = host.CurrentType.AsOdcmClass();
77
var entityName = this.GetEntityNameString(entity);
88

9-
var projection = host.CurrentType.Projection;
10-
var canExpand = projection.SupportsExpand();
11-
var canSelect = projection.BooleanValueOf("Selectable") != false;
9+
var features = host.CurrentType.GetFeatures();
1210

1311
#>
1412

@@ -28,14 +26,14 @@ namespace <#=this.GetNamespaceName(entity)#>
2826
<#=this.GetEntityGetAsyncMethod(entity, false)#>
2927

3028
<#
31-
if (canExpand)
29+
if (features.CanExpand)
3230
{
3331
Write(" ");
3432
Write(this.GetEntityWithReferenceExpandMethod(entity));
3533
Write("\n\n");
3634
}
3735

38-
if (canSelect)
36+
if (features.CanSelect)
3937
{
4038
Write(" ");
4139
Write(this.GetEntityWithReferenceSelectMethod(entity));

Templates/CSharp/Requests/IEntityCollectionRequest.cs.tt

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,7 @@ var collectionRequest = this.GetPropertyCollectionRequestName(prop);
99
var collectionResponse = string.Concat(prop.Class.Name.ToCheckedCase(), prop.Name.ToCheckedCase(), "CollectionResponse");
1010
var collectionPage = string.Concat(prop.Class.Name.ToCheckedCase(), prop.Name.ToCheckedCase(), "CollectionPage");
1111

12-
var projection = host.CurrentType.Projection;
13-
var canExpand = projection.SupportsExpand();
14-
var canSelect = projection.BooleanValueOf("Selectable") != false;
15-
var canFilter = projection.BooleanValueOf("Filterable") != false;
16-
var canUseTop = projection.BooleanValueOf("TopSupported") != false;
17-
var canSkip = projection.BooleanValueOf("SkipSupported") != false;
18-
var canSort = projection.BooleanValueOf("Sortable") != false;
19-
12+
var features = host.CurrentType.GetFeatures();
2013
#>
2114

2215
namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
@@ -43,7 +36,7 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
4336
/// <returns>The collection page.</returns>
4437
Task<I<#=collectionPage#>> GetAsync(CancellationToken cancellationToken);
4538

46-
<# if (canExpand) { #>
39+
<# if (features.CanExpand) { #>
4740
/// <summary>
4841
/// Adds the specified expand value to the request.
4942
/// </summary>
@@ -52,7 +45,7 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
5245
I<#=collectionRequest#> Expand(string value);
5346

5447
<# } #>
55-
<# if (canSelect) { #>
48+
<# if (features.CanSelect) { #>
5649
/// <summary>
5750
/// Adds the specified select value to the request.
5851
/// </summary>
@@ -61,7 +54,7 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
6154
I<#=collectionRequest#> Select(string value);
6255

6356
<# } #>
64-
<# if (canUseTop) { #>
57+
<# if (features.CanUseTop) { #>
6558
/// <summary>
6659
/// Adds the specified top value to the request.
6760
/// </summary>
@@ -70,7 +63,7 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
7063
I<#=collectionRequest#> Top(int value);
7164

7265
<# } #>
73-
<# if (canFilter) { #>
66+
<# if (features.CanFilter) { #>
7467
/// <summary>
7568
/// Adds the specified filter value to the request.
7669
/// </summary>
@@ -79,7 +72,7 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
7972
I<#=collectionRequest#> Filter(string value);
8073

8174
<# } #>
82-
<# if (canSkip) { #>
75+
<# if (features.CanSkip) { #>
8376
/// <summary>
8477
/// Adds the specified skip value to the request.
8578
/// </summary>
@@ -88,7 +81,7 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
8881
I<#=collectionRequest#> Skip(int value);
8982

9083
<# } #>
91-
<# if (canSort) { #>
84+
<# if (features.CanSort) { #>
9285
/// <summary>
9386
/// Adds the specified orderby value to the request.
9487
/// </summary>

Templates/CSharp/Requests/IEntityCollectionWithReferencesRequest.cs.tt

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@ var prop = host.CurrentType.AsOdcmProperty();
66
var collectionRequest = this.GetPropertyCollectionWithReferencesRequestName(prop);
77
var collectionPage = string.Concat(prop.Class.Name.ToCheckedCase(), prop.Name.ToCheckedCase(), "CollectionWithReferencesPage");
88

9-
var projection = host.CurrentType.Projection;
10-
var canExpand = projection.SupportsExpand();
11-
var canSelect = projection.BooleanValueOf("Selectable") != false;
12-
var canFilter = projection.BooleanValueOf("Filterable") != false;
13-
var canUseTop = projection.BooleanValueOf("TopSupported") != false;
14-
var canSkip = projection.BooleanValueOf("SkipSupported") != false;
15-
var canSort = projection.BooleanValueOf("Sortable") != false;
16-
9+
var features = host.CurrentType.GetFeatures();
1710
#>
1811

1912
namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
@@ -39,7 +32,7 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
3932
/// <returns>The collection page.</returns>
4033
Task<I<#=collectionPage#>> GetAsync(CancellationToken cancellationToken);
4134

42-
<# if (canExpand) { #>
35+
<# if (features.CanExpand) { #>
4336
/// <summary>
4437
/// Adds the specified expand value to the request.
4538
/// </summary>
@@ -48,7 +41,7 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
4841
I<#=collectionRequest#> Expand(string value);
4942

5043
<# } #>
51-
<# if (canSelect) { #>
44+
<# if (features.CanSelect) { #>
5245
/// <summary>
5346
/// Adds the specified select value to the request.
5447
/// </summary>
@@ -57,7 +50,7 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
5750
I<#=collectionRequest#> Select(string value);
5851

5952
<# } #>
60-
<# if (canUseTop) { #>
53+
<# if (features.CanUseTop) { #>
6154
/// <summary>
6255
/// Adds the specified top value to the request.
6356
/// </summary>
@@ -66,7 +59,7 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
6659
I<#=collectionRequest#> Top(int value);
6760

6861
<# } #>
69-
<# if (canFilter) { #>
62+
<# if (features.CanFilter) { #>
7063
/// <summary>
7164
/// Adds the specified filter value to the request.
7265
/// </summary>
@@ -75,7 +68,7 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
7568
I<#=collectionRequest#> Filter(string value);
7669

7770
<# } #>
78-
<# if (canSkip) { #>
71+
<# if (features.CanSkip) { #>
7972
/// <summary>
8073
/// Adds the specified skip value to the request.
8174
/// </summary>
@@ -84,7 +77,7 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
8477
I<#=collectionRequest#> Skip(int value);
8578

8679
<# } #>
87-
<# if (canSort) { #>
80+
<# if (features.CanSort) { #>
8881
/// <summary>
8982
/// Adds the specified orderby value to the request.
9083
/// </summary>

0 commit comments

Comments
 (0)