@@ -16,28 +16,79 @@ var entityName = method.Class.Name.ToCheckedCase();
16
16
var isFunction = method.IsFunction;
17
17
var isAction = !isFunction;
18
18
var isComposable = method.IsComposable;
19
+ var isCollection = method.IsCollection;
19
20
20
21
var methodName = method.Name.Substring(method.Name.IndexOf('.') + 1).ToCheckedCase();
21
22
var requestType = entityName + methodName + "Request";
22
23
23
- var returnEntityType = method.ReturnType == null ? null : method.ReturnType.GetTypeString(@namespace);
24
-
25
24
var returnEntityParameter = string.Empty;
26
- if (returnEntityType != null) {returnEntityParameter = returnEntityType.ToLower();}
27
25
28
- var isCollection = method.IsCollection;
26
+ // Represents the return of the SendAsync call within a public GetSync() or PostAsync() call.
27
+ var sendAsyncReturnType = string.Empty;
29
28
30
- var sendAsyncReturnType = isCollection
31
- ? "I" + entityName + methodName + "CollectionPage"
32
- : returnEntityType ;
29
+ // Indicates whether the OData method returns an OData primitive (non-collection).
30
+ // Collections of OData primitives is already supported.
31
+ var isPrimitiveReturnType = false ;
33
32
34
- var methodReturnType = sendAsyncReturnType == null
35
- ? "System.Threading.Tasks.Task"
36
- : "System.Threading.Tasks.Task<" + sendAsyncReturnType + ">";
33
+ // Represents the return type of a GetAsync() or PostAsync() call.
34
+ var returnEntityType = method.ReturnType == null ? null : method.ReturnType.GetTypeString(@namespace);
35
+
36
+ // Set the SendAsync return type and determine whether we are working with an OData primitive.
37
+ if (returnEntityType != null)
38
+ {
39
+ returnEntityParameter = returnEntityType.ToLower();
40
+ if (isCollection)
41
+ {
42
+ sendAsyncReturnType = "I" + entityName + methodName + "CollectionPage";
43
+ }
44
+ else
45
+ {
46
+ // Updates to supported OData primitives need to occur here,
47
+ // IMethodRequest.cs.tt, Microsoft.Graph.Core, and in
48
+ // GetMethodRequestPrimitiveReturnTypeString() in SharedCSharp.
49
+ sendAsyncReturnType = GetMethodRequestPrimitiveReturnTypeString(returnEntityType);
50
+
51
+ // These magic strings represent types in M.G.C.
52
+ if (sendAsyncReturnType == "ODataMethodStringResponse" ||
53
+ sendAsyncReturnType == "ODataMethodIntResponse" ||
54
+ sendAsyncReturnType == "ODataMethodBooleanResponse" ||
55
+ sendAsyncReturnType == "ODataMethodLongResponse")
56
+ {
57
+ isPrimitiveReturnType = true;
58
+ }
59
+ }
60
+ }
61
+ else
62
+ {
63
+ sendAsyncReturnType = returnEntityType;
64
+ }
65
+
66
+ // Set the return type of the public GetSync() or PostAsync() call.
67
+ var methodReturnType = string.Empty;
68
+ if (sendAsyncReturnType == null)
69
+ {
70
+ methodReturnType = "System.Threading.Tasks.Task";
71
+ }
72
+ else
73
+ {
74
+ if (isCollection)
75
+ {
76
+ var collectionPage = "I" + entityName + methodName + "CollectionPage";
77
+ methodReturnType = "System.Threading.Tasks.Task<" + collectionPage + ">";
78
+ }
79
+ else
80
+ {
81
+ var returnParameter = sendAsyncReturnType == "ODataMethodIntResponse" ||
82
+ sendAsyncReturnType == "ODataMethodBooleanResponse" ||
83
+ sendAsyncReturnType == "ODataMethodLongResponse" ? returnEntityType + "?"
84
+ : returnEntityType;
85
+ methodReturnType = "System.Threading.Tasks.Task<" + returnParameter + ">";
86
+ }
87
+ }
37
88
38
89
string methodOverloadReturnType = methodReturnType;
39
90
40
- if (isCollection)
91
+ if (isCollection || isPrimitiveReturnType )
41
92
{
42
93
methodReturnType = string.Concat("async ", methodReturnType);
43
94
}
@@ -178,9 +229,19 @@ namespace <#=@namespace#>
178
229
}
179
230
else if (!string.IsNullOrEmpty(sendAsyncReturnType))
180
231
{
232
+ if (isPrimitiveReturnType)
233
+ {
234
+ #>
235
+ var response = await this.SendAsync<<#=sendAsyncReturnType#>>(<#=methodParameter#>, cancellationToken);
236
+ return response.Value;
237
+ <#
238
+ }
239
+ else
240
+ {
181
241
#>
182
242
return this.SendAsync<<#=sendAsyncReturnType#>>(<#=methodParameter#>, cancellationToken);
183
243
<#
244
+ }
184
245
}
185
246
else
186
247
{
@@ -278,9 +339,19 @@ namespace <#=@namespace#>
278
339
}
279
340
else if (!string.IsNullOrEmpty(sendAsyncReturnType))
280
341
{
342
+ if (isPrimitiveReturnType)
343
+ {
344
+ #>
345
+ var response = await this.SendAsync<<#=sendAsyncReturnType#>>(null, cancellationToken);
346
+ return response.Value;
347
+ <#
348
+ }
349
+ else
350
+ {
281
351
#>
282
352
return this.SendAsync<<#=sendAsyncReturnType#>>(null, cancellationToken);
283
353
<#
354
+ }
284
355
}
285
356
else
286
357
{
0 commit comments