Skip to content

Commit 4173311

Browse files
author
Brian Melton
committed
2 parents 69ce9e9 + 6ccac3e commit 4173311

11 files changed

+284
-25
lines changed

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

Lines changed: 88 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,74 @@ public string GetSelectMethod(string requestType)
393393
return stringBuilder.ToString();
394394
}
395395

396+
public string GetSelectExpressionMethod(string requestType, string underlyingType)
397+
{
398+
var stringBuilder = new StringBuilder();
399+
400+
stringBuilder.Append(
401+
@"/// <summary>
402+
/// Adds the specified select value to the request.
403+
/// </summary>
404+
/// <param name=""selectExpression"">The expression from which to calculate the select value.</param>
405+
/// <returns>The request object to send.</returns>");
406+
stringBuilder.Append(Environment.NewLine);
407+
stringBuilder.AppendFormat(" public I{0} Select(Expression<Func<{1}, object>> selectExpression)", requestType, underlyingType);
408+
stringBuilder.Append(@"
409+
{
410+
if (selectExpression == null)
411+
{
412+
throw new ArgumentNullException(nameof(selectExpression));
413+
}
414+
string error;
415+
string value = ExpressionExtractHelper.ExtractMembers(selectExpression, out error);
416+
if (value == null)
417+
{
418+
throw new ArgumentException(error, nameof(selectExpression));
419+
}
420+
else
421+
{
422+
this.QueryOptions.Add(new QueryOption(""$select"", value));
423+
}
424+
return this;
425+
}");
426+
427+
return stringBuilder.ToString();
428+
}
429+
430+
public string GetExpandExpressionMethod(string requestType, string underlyingType)
431+
{
432+
var stringBuilder = new StringBuilder();
433+
434+
stringBuilder.Append(
435+
@"/// <summary>
436+
/// Adds the specified expand value to the request.
437+
/// </summary>
438+
/// <param name=""expandExpression"">The expression from which to calculate the expand value.</param>
439+
/// <returns>The request object to send.</returns>");
440+
stringBuilder.Append(Environment.NewLine);
441+
stringBuilder.AppendFormat(" public I{0} Expand(Expression<Func<{1}, object>> expandExpression)", requestType, underlyingType);
442+
stringBuilder.Append(@"
443+
{
444+
if (expandExpression == null)
445+
{
446+
throw new ArgumentNullException(nameof(expandExpression));
447+
}
448+
string error;
449+
string value = ExpressionExtractHelper.ExtractMembers(expandExpression, out error);
450+
if (value == null)
451+
{
452+
throw new ArgumentException(error, nameof(expandExpression));
453+
}
454+
else
455+
{
456+
this.QueryOptions.Add(new QueryOption(""$expand"", value));
457+
}
458+
return this;
459+
}");
460+
461+
return stringBuilder.ToString();
462+
}
463+
396464
public string GetExpandMethod(string requestType)
397465
{
398466
var stringBuilder = new StringBuilder();
@@ -415,25 +483,37 @@ public string GetExpandMethod(string requestType)
415483
}
416484

417485
// Standard entity
418-
public string GetEntityExpandMethod(OdcmClass odcmClass)
486+
public string GetEntityExpandMethods(OdcmClass odcmClass)
419487
{
420-
return this.GetExpandMethod(this.GetRequestString(this.GetEntityNameString(odcmClass)));
488+
string entityName = this.GetEntityNameString(odcmClass);
489+
return this.GetExpandMethod(this.GetRequestString(entityName)) +
490+
Environment.NewLine + Environment.NewLine + " " +
491+
this.GetExpandExpressionMethod(this.GetRequestString(entityName), entityName);
421492
}
422493

423-
public string GetEntitySelectMethod(OdcmClass odcmClass)
494+
public string GetEntitySelectMethods(OdcmClass odcmClass)
424495
{
425-
return this.GetSelectMethod(this.GetRequestString(this.GetEntityNameString(odcmClass)));
496+
string entityName = this.GetEntityNameString(odcmClass);
497+
return this.GetSelectMethod(this.GetRequestString(entityName)) +
498+
Environment.NewLine + Environment.NewLine + " " +
499+
this.GetSelectExpressionMethod(this.GetRequestString(entityName), entityName);
426500
}
427501

428502
// Entity with references
429-
public string GetEntityWithReferenceExpandMethod(OdcmClass odcmClass)
503+
public string GetEntityWithReferenceExpandMethods(OdcmClass odcmClass)
430504
{
431-
return this.GetExpandMethod(this.GetEntityWithReferenceRequestName(odcmClass));
505+
string entityWithReferenceRequestName = this.GetEntityWithReferenceRequestName(odcmClass);
506+
return this.GetExpandMethod(entityWithReferenceRequestName) +
507+
Environment.NewLine + Environment.NewLine + " " +
508+
this.GetExpandExpressionMethod(entityWithReferenceRequestName, this.GetEntityNameString(odcmClass));
432509
}
433510

434-
public string GetEntityWithReferenceSelectMethod(OdcmClass odcmClass)
511+
public string GetEntityWithReferenceSelectMethods(OdcmClass odcmClass)
435512
{
436-
return this.GetSelectMethod(this.GetEntityWithReferenceRequestName(odcmClass));
513+
string entityWithReferenceRequestName = this.GetEntityWithReferenceRequestName(odcmClass);
514+
return this.GetSelectMethod(this.GetEntityWithReferenceRequestName(odcmClass)) +
515+
Environment.NewLine + Environment.NewLine + " " +
516+
this.GetSelectExpressionMethod(entityWithReferenceRequestName, this.GetEntityNameString(odcmClass));
437517
}
438518

439519
#>

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

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,22 @@ public string GetEntityUpdateAsyncMethod(OdcmClass odcmClass)
262262
// Build select and expand methods
263263
// -------------------------------------------------------------
264264

265+
public string GetExpandExpressionMethod(string requestType, string underlyingType)
266+
{
267+
var stringBuilder = new StringBuilder();
268+
269+
stringBuilder.Append(
270+
@"/// <summary>
271+
/// Adds the specified expand value to the request.
272+
/// </summary>
273+
/// <param name=""expandExpression"">The expression from which to calculate the expand value.</param>
274+
/// <returns>The request object to send.</returns>");
275+
stringBuilder.Append(Environment.NewLine);
276+
stringBuilder.AppendFormat(" I{0} Expand(Expression<Func<{1}, object>> expandExpression);", requestType, underlyingType);
277+
278+
return stringBuilder.ToString();
279+
}
280+
265281
public string GetExpandMethod(string entityRequest)
266282
{
267283
var stringBuilder = new StringBuilder();
@@ -274,7 +290,23 @@ public string GetExpandMethod(string entityRequest)
274290
/// <returns>The request object to send.</returns>");
275291
stringBuilder.Append(Environment.NewLine);
276292
stringBuilder.AppendFormat(" I{0} Expand(string value);", entityRequest);
293+
294+
return stringBuilder.ToString();
295+
}
296+
297+
public string GetSelectExpressionMethod(string requestType, string underlyingType)
298+
{
299+
var stringBuilder = new StringBuilder();
277300

301+
stringBuilder.Append(
302+
@"/// <summary>
303+
/// Adds the specified select value to the request.
304+
/// </summary>
305+
/// <param name=""selectExpression"">The expression from which to calculate the select value.</param>
306+
/// <returns>The request object to send.</returns>");
307+
stringBuilder.Append(Environment.NewLine);
308+
stringBuilder.AppendFormat(" I{0} Select(Expression<Func<{1}, object>> selectExpression);", requestType, underlyingType);
309+
278310
return stringBuilder.ToString();
279311
}
280312

@@ -290,30 +322,42 @@ public string GetSelectMethod(string entityRequest)
290322
/// <returns>The request object to send.</returns>");
291323
stringBuilder.Append(Environment.NewLine);
292324
stringBuilder.AppendFormat(" I{0} Select(string value);", entityRequest);
293-
325+
294326
return stringBuilder.ToString();
295327
}
296328

297329
// Standard entity
298-
public string GetEntityExpandMethod(OdcmClass odcmClass)
330+
public string GetEntityExpandMethods(OdcmClass odcmClass)
299331
{
300-
return this.GetExpandMethod(this.GetRequestString(this.GetEntityNameString(odcmClass)));
332+
string entityName = this.GetEntityNameString(odcmClass);
333+
return this.GetExpandMethod(this.GetRequestString(entityName)) +
334+
Environment.NewLine + Environment.NewLine + " " +
335+
this.GetExpandExpressionMethod(this.GetRequestString(entityName), entityName);
301336
}
302337

303-
public string GetEntitySelectMethod(OdcmClass odcmClass)
338+
public string GetEntitySelectMethods(OdcmClass odcmClass)
304339
{
305-
return this.GetSelectMethod(this.GetRequestString(this.GetEntityNameString(odcmClass)));
340+
string entityName = this.GetEntityNameString(odcmClass);
341+
return this.GetSelectMethod(this.GetRequestString(entityName)) +
342+
Environment.NewLine + Environment.NewLine + " " +
343+
this.GetSelectExpressionMethod(this.GetRequestString(entityName), entityName);
306344
}
307345

308346
// Entity with references
309-
public string GetEntityWithReferenceExpandMethod(OdcmClass odcmClass)
347+
public string GetEntityWithReferenceExpandMethods(OdcmClass odcmClass)
310348
{
311-
return this.GetExpandMethod(this.GetEntityWithReferenceRequestName(odcmClass));
349+
string entityWithReferenceRequestName = this.GetEntityWithReferenceRequestName(odcmClass);
350+
return this.GetExpandMethod(entityWithReferenceRequestName) +
351+
Environment.NewLine + Environment.NewLine + " " +
352+
this.GetExpandExpressionMethod(entityWithReferenceRequestName, this.GetEntityNameString(odcmClass));
312353
}
313354

314-
public string GetEntityWithReferenceSelectMethod(OdcmClass odcmClass)
355+
public string GetEntityWithReferenceSelectMethods(OdcmClass odcmClass)
315356
{
316-
return this.GetSelectMethod(this.GetEntityWithReferenceRequestName(odcmClass));
357+
string entityWithReferenceRequestName = this.GetEntityWithReferenceRequestName(odcmClass);
358+
return this.GetSelectMethod(entityWithReferenceRequestName) +
359+
Environment.NewLine + Environment.NewLine + " " +
360+
this.GetSelectExpressionMethod(entityWithReferenceRequestName, this.GetEntityNameString(odcmClass));
317361
}
318362

319363
#>

Templates/CSharp/Requests/EntityCollectionRequest.cs.tt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace <#=this.GetNamespaceName(prop.Class.AsOdcmClass())#>
1717
using System.Collections.Generic;
1818
using System.Net.Http;
1919
using System.Threading;
20+
using System.Linq.Expressions;
2021

2122
<#=this.GetCollectionClassDefinition(prop)#>
2223
{
@@ -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
<# } #>
82107
<# if (features.CanSelect) { #>
83108
/// <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
<# } #>
95144
<# if (features.CanUseTop) { #>
96145
/// <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.Collections.Generic;
2121
using System.Net.Http;
2222
using System.Threading;
23+
using System.Linq.Expressions;
2324

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

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

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

Templates/CSharp/Requests/EntityRequest.cs.tt

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

2122
<#=this.GetEntityRequestClassDefinition(entity)#>
2223
{
@@ -51,14 +52,14 @@ namespace <#=this.GetNamespaceName(entity)#>
5152
if (features.CanExpand)
5253
{
5354
Write(" ");
54-
Write(this.GetEntityExpandMethod(entity));
55+
Write(this.GetEntityExpandMethods(entity));
5556
Write("\n\n");
5657
}
5758

5859
if (features.CanSelect)
5960
{
6061
Write(" ");
61-
Write(this.GetEntitySelectMethod(entity));
62+
Write(this.GetEntitySelectMethods(entity));
6263
Write("\n\n");
6364
}
6465
#>

0 commit comments

Comments
 (0)