Release: Fix OData methods with OData primitive return type (#300) by MIchaelMainer · Pull Request #307 · microsoftgraph/MSGraph-SDK-Code-Generator
Expand Up
@@ -16,28 +16,79 @@ var entityName = method.Class.Name.ToCheckedCase();
var isFunction = method.IsFunction;
var isAction = !isFunction;
var isComposable = method.IsComposable;
var isCollection = method.IsCollection;
var methodName = method.Name.Substring(method.Name.IndexOf('.') + 1).ToCheckedCase(); var requestType = entityName + methodName + "Request";
var returnEntityType = method.ReturnType == null ? null : method.ReturnType.GetTypeString(@namespace);
var returnEntityParameter = string.Empty; if (returnEntityType != null) {returnEntityParameter = returnEntityType.ToLower();}
var isCollection = method.IsCollection; // Represents the return of the SendAsync call within a public GetSync() or PostAsync() call. var sendAsyncReturnType = string.Empty;
var sendAsyncReturnType = isCollection ? "I" + entityName + methodName + "CollectionPage" : returnEntityType; // Indicates whether the OData method returns an OData primitive (non-collection). // Collections of OData primitives is already supported. var isPrimitiveReturnType = false;
var methodReturnType = sendAsyncReturnType == null ? "System.Threading.Tasks.Task" : "System.Threading.Tasks.Task<" + sendAsyncReturnType + ">"; // Represents the return type of a GetAsync() or PostAsync() call. var returnEntityType = method.ReturnType == null ? null : method.ReturnType.GetTypeString(@namespace);
// Set the SendAsync return type and determine whether we are working with an OData primitive. if (returnEntityType != null) { returnEntityParameter = returnEntityType.ToLower(); if (isCollection) { sendAsyncReturnType = "I" + entityName + methodName + "CollectionPage"; } else { // Updates to supported OData primitives need to occur here, // IMethodRequest.cs.tt, Microsoft.Graph.Core, and in // GetMethodRequestPrimitiveReturnTypeString() in SharedCSharp. sendAsyncReturnType = GetMethodRequestPrimitiveReturnTypeString(returnEntityType);
// These magic strings represent types in M.G.C. if (sendAsyncReturnType == "ODataMethodStringResponse" || sendAsyncReturnType == "ODataMethodIntResponse" || sendAsyncReturnType == "ODataMethodBooleanResponse" || sendAsyncReturnType == "ODataMethodLongResponse") { isPrimitiveReturnType = true; } } } else { sendAsyncReturnType = returnEntityType; }
// Set the return type of the public GetSync() or PostAsync() call. var methodReturnType = string.Empty; if (sendAsyncReturnType == null) { methodReturnType = "System.Threading.Tasks.Task"; } else { if (isCollection) { var collectionPage = "I" + entityName + methodName + "CollectionPage"; methodReturnType = "System.Threading.Tasks.Task<" + collectionPage + ">"; } else { var returnParameter = sendAsyncReturnType == "ODataMethodIntResponse" || sendAsyncReturnType == "ODataMethodBooleanResponse" || sendAsyncReturnType == "ODataMethodLongResponse" ? returnEntityType + "?" : returnEntityType; methodReturnType = "System.Threading.Tasks.Task<" + returnParameter + ">"; } }
string methodOverloadReturnType = methodReturnType;
if (isCollection) if (isCollection || isPrimitiveReturnType) { methodReturnType = string.Concat("async ", methodReturnType); } Expand Down Expand Up @@ -178,9 +229,19 @@ namespace <#=@namespace#> } else if (!string.IsNullOrEmpty(sendAsyncReturnType)) { if (isPrimitiveReturnType) { #> var response = await this.SendAsync<<#=sendAsyncReturnType#>>(<#=methodParameter#>, cancellationToken); return response.Value; <# } else { #> return this.SendAsync<<#=sendAsyncReturnType#>>(<#=methodParameter#>, cancellationToken); <# } } else { Expand Down Expand Up @@ -278,9 +339,19 @@ namespace <#=@namespace#> } else if (!string.IsNullOrEmpty(sendAsyncReturnType)) { if (isPrimitiveReturnType) { #> var response = await this.SendAsync<<#=sendAsyncReturnType#>>(null, cancellationToken); return response.Value; <# } else { #> return this.SendAsync<<#=sendAsyncReturnType#>>(null, cancellationToken); <# } } else { Expand Down
var methodName = method.Name.Substring(method.Name.IndexOf('.') + 1).ToCheckedCase(); var requestType = entityName + methodName + "Request";
var returnEntityType = method.ReturnType == null ? null : method.ReturnType.GetTypeString(@namespace);
var returnEntityParameter = string.Empty; if (returnEntityType != null) {returnEntityParameter = returnEntityType.ToLower();}
var isCollection = method.IsCollection; // Represents the return of the SendAsync call within a public GetSync() or PostAsync() call. var sendAsyncReturnType = string.Empty;
var sendAsyncReturnType = isCollection ? "I" + entityName + methodName + "CollectionPage" : returnEntityType; // Indicates whether the OData method returns an OData primitive (non-collection). // Collections of OData primitives is already supported. var isPrimitiveReturnType = false;
var methodReturnType = sendAsyncReturnType == null ? "System.Threading.Tasks.Task" : "System.Threading.Tasks.Task<" + sendAsyncReturnType + ">"; // Represents the return type of a GetAsync() or PostAsync() call. var returnEntityType = method.ReturnType == null ? null : method.ReturnType.GetTypeString(@namespace);
// Set the SendAsync return type and determine whether we are working with an OData primitive. if (returnEntityType != null) { returnEntityParameter = returnEntityType.ToLower(); if (isCollection) { sendAsyncReturnType = "I" + entityName + methodName + "CollectionPage"; } else { // Updates to supported OData primitives need to occur here, // IMethodRequest.cs.tt, Microsoft.Graph.Core, and in // GetMethodRequestPrimitiveReturnTypeString() in SharedCSharp. sendAsyncReturnType = GetMethodRequestPrimitiveReturnTypeString(returnEntityType);
// These magic strings represent types in M.G.C. if (sendAsyncReturnType == "ODataMethodStringResponse" || sendAsyncReturnType == "ODataMethodIntResponse" || sendAsyncReturnType == "ODataMethodBooleanResponse" || sendAsyncReturnType == "ODataMethodLongResponse") { isPrimitiveReturnType = true; } } } else { sendAsyncReturnType = returnEntityType; }
// Set the return type of the public GetSync() or PostAsync() call. var methodReturnType = string.Empty; if (sendAsyncReturnType == null) { methodReturnType = "System.Threading.Tasks.Task"; } else { if (isCollection) { var collectionPage = "I" + entityName + methodName + "CollectionPage"; methodReturnType = "System.Threading.Tasks.Task<" + collectionPage + ">"; } else { var returnParameter = sendAsyncReturnType == "ODataMethodIntResponse" || sendAsyncReturnType == "ODataMethodBooleanResponse" || sendAsyncReturnType == "ODataMethodLongResponse" ? returnEntityType + "?" : returnEntityType; methodReturnType = "System.Threading.Tasks.Task<" + returnParameter + ">"; } }
string methodOverloadReturnType = methodReturnType;
if (isCollection) if (isCollection || isPrimitiveReturnType) { methodReturnType = string.Concat("async ", methodReturnType); } Expand Down Expand Up @@ -178,9 +229,19 @@ namespace <#=@namespace#> } else if (!string.IsNullOrEmpty(sendAsyncReturnType)) { if (isPrimitiveReturnType) { #> var response = await this.SendAsync<<#=sendAsyncReturnType#>>(<#=methodParameter#>, cancellationToken); return response.Value; <# } else { #> return this.SendAsync<<#=sendAsyncReturnType#>>(<#=methodParameter#>, cancellationToken); <# } } else { Expand Down Expand Up @@ -278,9 +339,19 @@ namespace <#=@namespace#> } else if (!string.IsNullOrEmpty(sendAsyncReturnType)) { if (isPrimitiveReturnType) { #> var response = await this.SendAsync<<#=sendAsyncReturnType#>>(null, cancellationToken); return response.Value; <# } else { #> return this.SendAsync<<#=sendAsyncReturnType#>>(null, cancellationToken); <# } } else { Expand Down