public static string GetFunctionImportsCode(IEdmModel model, string proxyClassNamespace, string proxyClassName, string endpointUri, Constants.FunctionImportsGenerator generator = Constants.FunctionImportsGenerator.Inner) { _proxyClassNamespace = proxyClassNamespace; var declaredEntityContainer = model.FindDeclaredEntityContainer(proxyClassName); var functionImports = declaredEntityContainer.FunctionImports().ToList(); var functionMethods = new StringBuilder(); functionMethods.AppendLine("\t\t#region FunctionImports"); functionMethods.AppendLine(); foreach (var functionImport in functionImports) { var functionImportModel = new FunctionImportModel(model, functionImport, endpointUri, _proxyClassNamespace); var functionRegion = string.Empty; switch (generator) { case Constants.FunctionImportsGenerator.Inner: functionRegion = GetFunctionMethodRegionWithInnerMethods(functionImportModel); break; case Constants.FunctionImportsGenerator.SimpleOData: functionRegion = GetFunctionMethodRegionWithSimpleOdataClient(functionImportModel); break; case Constants.FunctionImportsGenerator.Vipr: //ToDo: need to add functionRegion = string.Empty; break; } functionMethods.AppendLine(functionRegion); } functionMethods.Append("\t\t#endregion"); return(functionMethods.ToString()); }
private static string GetFunctionMethodRegionWithInnerMethods(FunctionImportModel functionImportModel) { if (functionImportModel.FunctionImport.IsBindable) { return(string.Empty); } var methodName = functionImportModel.EntitySetName + functionImportModel.FunctionImport.Name; var realFunctionImportReturnType = functionImportModel.FunctionReturnType?.ToCodeStringType(_proxyClassNamespace); var functionRegion = new StringBuilder(); functionRegion.AppendLine($"\t\t#region {methodName}Async"); functionRegion.AppendLine(); //// skip the first parameter for a bound function //if (functionImportModel.HasParameters && functionImportModel.FunctionImport.IsBindable) // functionImportModel.FunctionParameters.Remove(functionImportModel.BindableParameter); // add model class if parameters count gt 0 if (functionImportModel.HasParameters) { functionRegion.AppendLine(GetModelRegion($"{methodName}Model", functionImportModel.FunctionParameters, functionImportModel.FunctionImport.IsBindable)); } functionRegion.AppendLine(); if (functionImportModel.FunctionReturnType == null) { functionRegion.AppendLine($"\t\tpublic async Task<ODataStandartResponse> {methodName}Async({(functionImportModel.HasParameters ? $"{methodName}Model model" : string.Empty)})"); functionRegion.AppendLine("\t\t{"); functionRegion.AppendLine($"\t\t\treturn await this.CallOdataMethodWithVoidResultAsync("); } else { functionRegion.AppendLine($"\t\tpublic async Task<(ODataStandartResponse OdataResponse, {realFunctionImportReturnType} ODataResult)> {methodName}Async({(functionImportModel.HasParameters ? $"{methodName}Model model)" : ")")}"); functionRegion.AppendLine("\t\t{"); functionRegion.AppendLine($"\t\t\treturn await this.{(functionImportModel.FunctionReturnType.IsCollection() ? "CallOdataMethodWithMultipleResultAsync" : "CallOdataMethodWithSingleResultAsync")}<{(functionImportModel.FunctionReturnType.IsCollection() ? $"{realFunctionImportReturnType.Replace("IEnumerable<", string.Empty).Replace(">", string.Empty)}" : $"{realFunctionImportReturnType}")}, {methodName}Model>(");