Skip to content

Commit 1404f9f

Browse files
committed
Partial updates to generator
Update many of the generator methods to create Select methods using linq expressions.
1 parent 35e31fa commit 1404f9f

9 files changed

+217
-20
lines changed

Templates/CSharp/Base/EntityRequest.Base.template.tt

Lines changed: 86 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,74 @@ public string GetSelectMethod(string requestType)
328328
return stringBuilder.ToString();
329329
}
330330

331+
public string GetSelectExpressionMethod(string requestType, string underlyingType)
332+
{
333+
var stringBuilder = new StringBuilder();
334+
335+
stringBuilder.Append(
336+
@"/// <summary>
337+
/// Adds the specified select value to the request.
338+
/// </summary>
339+
/// <param name=""selectExpression"">The expression from which to calculate the select value.</param>
340+
/// <returns>The request object to send.</returns>");
341+
stringBuilder.Append(Environment.NewLine);
342+
stringBuilder.AppendFormat(" public I{0} Select(Expression<Func<{1}, object>> selectExpression)", requestType, underlyingType);
343+
stringBuilder.Append(@"
344+
{
345+
if (selectExpression == null)
346+
{
347+
throw new ArgumentNullException(nameof(selectExpression));
348+
}
349+
string error;
350+
string value = ExpressionExtractHelper.ExtractMembers(selectExpression, out error);
351+
if (value == null)
352+
{
353+
throw new ArgumentException(error, nameof(selectExpression));
354+
}
355+
else
356+
{
357+
this.QueryOptions.Add(new QueryOption(""$select"", value));
358+
}
359+
return this;
360+
}");
361+
362+
return stringBuilder.ToString();
363+
}
364+
365+
public string GetExpandExpressionMethod(string requestType, string underlyingType)
366+
{
367+
var stringBuilder = new StringBuilder();
368+
369+
stringBuilder.Append(
370+
@"/// <summary>
371+
/// Adds the specified expand value to the request.
372+
/// </summary>
373+
/// <param name=""expandExpression"">The expression from which to calculate the expand value.</param>
374+
/// <returns>The request object to send.</returns>");
375+
stringBuilder.Append(Environment.NewLine);
376+
stringBuilder.AppendFormat(" public I{0} Expand(Expression<Func<{1}, object>> expandExpression)", requestType, underlyingType);
377+
stringBuilder.Append(@"
378+
{
379+
if (expandExpression == null)
380+
{
381+
throw new ArgumentNullException(nameof(expandExpression));
382+
}
383+
string error;
384+
string value = ExpressionExtractHelper.ExtractMembers(expandExpression, out error);
385+
if (value == null)
386+
{
387+
throw new ArgumentException(error, nameof(expandExpression));
388+
}
389+
else
390+
{
391+
this.QueryOptions.Add(new QueryOption(""$expand"", value));
392+
}
393+
return this;
394+
}");
395+
396+
return stringBuilder.ToString();
397+
}
398+
331399
public string GetExpandMethod(string requestType)
332400
{
333401
var stringBuilder = new StringBuilder();
@@ -350,25 +418,35 @@ public string GetExpandMethod(string requestType)
350418
}
351419

352420
// Standard entity
353-
public string GetEntityExpandMethod(OdcmClass odcmClass)
421+
public string GetEntityExpandMethods(OdcmClass odcmClass)
354422
{
355-
return this.GetExpandMethod(this.GetRequestString(this.GetEntityNameString(odcmClass)));
423+
string entityName = this.GetEntityNameString(odcmClass);
424+
return this.GetExpandMethod(this.GetRequestString(this.GetEntityNameString(odcmClass))) +
425+
Environment.NewLine + Environment.NewLine + " " +
426+
this.GetExpandExpressionMethod(this.GetRequestString(entityName), entityName);
356427
}
357428

358-
public string GetEntitySelectMethod(OdcmClass odcmClass)
429+
public string GetEntitySelectMethods(OdcmClass odcmClass)
359430
{
360-
return this.GetSelectMethod(this.GetRequestString(this.GetEntityNameString(odcmClass)));
431+
string entityName = this.GetEntityNameString(odcmClass);
432+
return this.GetSelectMethod(this.GetRequestString(this.GetEntityNameString(odcmClass))) +
433+
Environment.NewLine + Environment.NewLine + " " +
434+
this.GetSelectExpressionMethod(this.GetRequestString(entityName), entityName);
361435
}
362436

363437
// Entity with references
364-
public string GetEntityWithReferenceExpandMethod(OdcmClass odcmClass)
438+
public string GetEntityWithReferenceExpandMethods(OdcmClass odcmClass)
365439
{
366-
return this.GetExpandMethod(this.GetEntityWithReferenceRequestName(odcmClass));
440+
return this.GetExpandMethod(this.GetEntityWithReferenceRequestName(odcmClass)) +
441+
Environment.NewLine + Environment.NewLine + " " +
442+
this.GetExpandExpressionMethod(this.GetEntityWithReferenceRequestName(odcmClass), this.GetEntityNameString(odcmClass));
367443
}
368444

369-
public string GetEntityWithReferenceSelectMethod(OdcmClass odcmClass)
445+
public string GetEntityWithReferenceSelectMethods(OdcmClass odcmClass)
370446
{
371-
return this.GetSelectMethod(this.GetEntityWithReferenceRequestName(odcmClass));
447+
return this.GetSelectMethod(this.GetEntityWithReferenceRequestName(odcmClass)) +
448+
Environment.NewLine + Environment.NewLine + " " +
449+
this.GetSelectExpressionMethod(this.GetEntityWithReferenceRequestName(odcmClass), this.GetEntityNameString(odcmClass));
372450
}
373451

374452
#>

Templates/CSharp/Base/IEntityRequest.Base.template.tt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ public string GetExpandMethod(string entityRequest)
229229
/// <returns>The request object to send.</returns>");
230230
stringBuilder.Append(Environment.NewLine);
231231
stringBuilder.AppendFormat(" I{0} Expand(string value);", entityRequest);
232+
stringBuilder.Append("TODO ExpandExpression");
232233

233234
return stringBuilder.ToString();
234235
}
@@ -245,28 +246,29 @@ public string GetSelectMethod(string entityRequest)
245246
/// <returns>The request object to send.</returns>");
246247
stringBuilder.Append(Environment.NewLine);
247248
stringBuilder.AppendFormat(" I{0} Select(string value);", entityRequest);
249+
stringBuilder.Append("TODO SelectExpression");
248250

249251
return stringBuilder.ToString();
250252
}
251253

252254
// Standard entity
253-
public string GetEntityExpandMethod(OdcmClass odcmClass)
255+
public string GetEntityExpandMethods(OdcmClass odcmClass)
254256
{
255257
return this.GetExpandMethod(this.GetRequestString(this.GetEntityNameString(odcmClass)));
256258
}
257259

258-
public string GetEntitySelectMethod(OdcmClass odcmClass)
260+
public string GetEntitySelectMethods(OdcmClass odcmClass)
259261
{
260262
return this.GetSelectMethod(this.GetRequestString(this.GetEntityNameString(odcmClass)));
261263
}
262264

263265
// Entity with references
264-
public string GetEntityWithReferenceExpandMethod(OdcmClass odcmClass)
266+
public string GetEntityWithReferenceExpandMethods(OdcmClass odcmClass)
265267
{
266268
return this.GetExpandMethod(this.GetEntityWithReferenceRequestName(odcmClass));
267269
}
268270

269-
public string GetEntityWithReferenceSelectMethod(OdcmClass odcmClass)
271+
public string GetEntityWithReferenceSelectMethods(OdcmClass odcmClass)
270272
{
271273
return this.GetSelectMethod(this.GetEntityWithReferenceRequestName(odcmClass));
272274
}

Templates/CSharp/Requests/EntityCollectionRequest.cs.tt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
1818
using System.Net.Http;
1919
using System.Threading;
2020
using System.Threading.Tasks;
21+
using System.Linq.Expressions;
2122

2223
<#=this.GetCollectionClassDefinition(prop)#>
2324
{
@@ -78,6 +79,30 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
7879
return this;
7980
}
8081

82+
/// <summary>
83+
/// Adds the specified expand value to the request.
84+
/// </summary>
85+
/// <param name="expandExpression">The expression from which to calculate the expand value.</param>
86+
/// <returns>The request object to send.</returns>
87+
public I<#=collectionRequest#> Expand(Expression<Func<<#=innerEntityType#>, object>> expandExpression)
88+
{
89+
if (expandExpression == null)
90+
{
91+
throw new ArgumentNullException(nameof(expandExpression));
92+
}
93+
string error;
94+
string value = ExpressionExtractHelper.ExtractMembers(expandExpression, out error);
95+
if (value == null)
96+
{
97+
throw new ArgumentException(error, nameof(expandExpression));
98+
}
99+
else
100+
{
101+
this.QueryOptions.Add(new QueryOption("$expand", value));
102+
}
103+
return this;
104+
}
105+
81106
/// <summary>
82107
/// Adds the specified select value to the request.
83108
/// </summary>
@@ -89,6 +114,30 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
89114
return this;
90115
}
91116

117+
/// <summary>
118+
/// Adds the specified select value to the request.
119+
/// </summary>
120+
/// <param name="selectExpression">The expression from which to calculate the select value.</param>
121+
/// <returns>The request object to send.</returns>
122+
public I<#=collectionRequest#> Select(Expression<Func<<#=innerEntityType#>, object>> selectExpression)
123+
{
124+
if (selectExpression == null)
125+
{
126+
throw new ArgumentNullException(nameof(selectExpression));
127+
}
128+
string error;
129+
string value = ExpressionExtractHelper.ExtractMembers(selectExpression, out error);
130+
if (value == null)
131+
{
132+
throw new ArgumentException(error, nameof(selectExpression));
133+
}
134+
else
135+
{
136+
this.QueryOptions.Add(new QueryOption("$select", value));
137+
}
138+
return this;
139+
}
140+
92141
/// <summary>
93142
/// Adds the specified top value to the request.
94143
/// </summary>

Templates/CSharp/Requests/EntityCollectionWithReferencesRequest.cs.tt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
2020
using System.Net.Http;
2121
using System.Threading;
2222
using System.Threading.Tasks;
23+
using System.Linq.Expressions;
2324

2425
<#=this.GetCollectionWithReferencesClassDefinition(prop)#>
2526
{
@@ -80,6 +81,30 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
8081
return this;
8182
}
8283

84+
/// <summary>
85+
/// Adds the specified expand value to the request.
86+
/// </summary>
87+
/// <param name="expandExpression">The expression from which to calculate the expand value.</param>
88+
/// <returns>The request object to send.</returns>
89+
public I<#=collectionRequest#> Expand(Expression<Func<<#=innerEntityType#>, object>> expandExpression)
90+
{
91+
if (expandExpression == null)
92+
{
93+
throw new ArgumentNullException(nameof(expandExpression));
94+
}
95+
string error;
96+
string value = ExpressionExtractHelper.ExtractMembers(expandExpression, out error);
97+
if (value == null)
98+
{
99+
throw new ArgumentException(error, nameof(expandExpression));
100+
}
101+
else
102+
{
103+
this.QueryOptions.Add(new QueryOption("$expand", value));
104+
}
105+
return this;
106+
}
107+
83108
/// <summary>
84109
/// Adds the specified select value to the request.
85110
/// </summary>
@@ -91,6 +116,30 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
91116
return this;
92117
}
93118

119+
/// <summary>
120+
/// Adds the specified select value to the request.
121+
/// </summary>
122+
/// <param name="selectExpression">The expression from which to calculate the select value.</param>
123+
/// <returns>The request object to send.</returns>
124+
public I<#=collectionRequest#> Select(Expression<Func<<#=innerEntityType#>, object>> selectExpression)
125+
{
126+
if (selectExpression == null)
127+
{
128+
throw new ArgumentNullException(nameof(selectExpression));
129+
}
130+
string error;
131+
string value = ExpressionExtractHelper.ExtractMembers(selectExpression, out error);
132+
if (value == null)
133+
{
134+
throw new ArgumentException(error, nameof(selectExpression));
135+
}
136+
else
137+
{
138+
this.QueryOptions.Add(new QueryOption("$select", value));
139+
}
140+
return this;
141+
}
142+
94143
/// <summary>
95144
/// Adds the specified top value to the request.
96145
/// </summary>

Templates/CSharp/Requests/EntityRequest.cs.tt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace <#=this.GetNamespaceName(entity)#>
1616
using System.Net.Http;
1717
using System.Threading;
1818
using System.Threading.Tasks;
19+
using System.Linq.Expressions;
1920

2021
<#=this.GetEntityRequestClassDefinition(entity)#>
2122
{
@@ -29,9 +30,9 @@ namespace <#=this.GetNamespaceName(entity)#>
2930

3031
<#=this.GetEntityUpdateAsyncMethod(entity)#>
3132

32-
<#=this.GetEntityExpandMethod(entity)#>
33+
<#=this.GetEntityExpandMethods(entity)#>
3334

34-
<#=this.GetEntitySelectMethod(entity)#>
35+
<#=this.GetEntitySelectMethods(entity)#>
3536

3637
/// <summary>
3738
/// Initializes any collection properties after deserialization, like next requests for paging.

Templates/CSharp/Requests/EntityWithReferenceRequest.cs.tt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@ namespace <#=this.GetNamespaceName(entity)#>
1616
using System.Net.Http;
1717
using System.Threading;
1818
using System.Threading.Tasks;
19+
using System.Linq.Expressions;
1920

2021
<#=this.GetEntityWithReferenceRequestClassDefinition(entity)#>
2122
{
2223
<#=this.GetEntityWithReferenceRequestConstructor(entity)#>
2324

2425
<#=this.GetEntityGetAsyncMethod(entity, false)#>
2526

26-
<#=this.GetEntityWithReferenceExpandMethod(entity)#>
27+
<#=this.GetEntityWithReferenceExpandMethods(entity)#>
2728

28-
<#=this.GetEntityWithReferenceSelectMethod(entity)#>
29+
<#=this.GetEntityWithReferenceSelectMethods(entity)#>
2930
}
3031
}

Templates/CSharp/Requests/IEntityCollectionRequest.cs.tt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
1818
using System.Net.Http;
1919
using System.Threading;
2020
using System.Threading.Tasks;
21+
using System.Linq.Expressions;
2122

2223
<#=this.GetCollectionInterfaceDefinition(prop)#>
2324
{
@@ -42,13 +43,27 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
4243
/// <returns>The request object to send.</returns>
4344
I<#=collectionRequest#> Expand(string value);
4445

46+
/// <summary>
47+
/// Adds the specified expand value to the request.
48+
/// </summary>
49+
/// <param name="expandExpression">The expression from which to calculate the expand value.</param>
50+
/// <returns>The request object to send.</returns>
51+
I<#=collectionRequest#> Expand(Expression<Func<<#=innerEntityType#>, object>> expandExpression);
52+
4553
/// <summary>
4654
/// Adds the specified select value to the request.
4755
/// </summary>
4856
/// <param name="value">The select value.</param>
4957
/// <returns>The request object to send.</returns>
5058
I<#=collectionRequest#> Select(string value);
5159

60+
/// <summary>
61+
/// Adds the specified select value to the request.
62+
/// </summary>
63+
/// <param name="selectExpression">The expression from which to calculate the select value.</param>
64+
/// <returns>The request object to send.</returns>
65+
I<#=collectionRequest#> Select(Expression<Func<<#=innerEntityType#>, object>> selectExpression);
66+
5267
/// <summary>
5368
/// Adds the specified top value to the request.
5469
/// </summary>

Templates/CSharp/Requests/IEntityRequest.cs.tt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace <#=this.GetNamespaceName(entity)#>
1515
using System.Net.Http;
1616
using System.Threading;
1717
using System.Threading.Tasks;
18+
using System.Linq.Expressions;
1819

1920
<#=this.GetEntityRequestInterfaceDefinition(entity)#>
2021
{
@@ -26,8 +27,8 @@ namespace <#=this.GetNamespaceName(entity)#>
2627

2728
<#=this.GetEntityUpdateAsyncMethod(entity)#>
2829

29-
<#=this.GetEntityExpandMethod(entity)#>
30+
<#=this.GetEntityExpandMethods(entity)#>
3031

31-
<#=this.GetEntitySelectMethod(entity)#>
32+
<#=this.GetEntitySelectMethods(entity)#>
3233
}
3334
}

0 commit comments

Comments
 (0)