diff --git a/CHANGELOG.md b/CHANGELOG.md index 01068b4d5c..30ce596928 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - TypeScript imports are now using ES6 imports with the .js extension. +- Remove LINQ usage in generated code. ## [1.15.0] - 2024-06-06 diff --git a/it/csharp/dotnet.csproj b/it/csharp/dotnet.csproj index 1b47f2c09f..a79f9605bd 100644 --- a/it/csharp/dotnet.csproj +++ b/it/csharp/dotnet.csproj @@ -21,4 +21,4 @@ - \ No newline at end of file + diff --git a/src/Kiota.Builder/Refiners/CSharpRefiner.cs b/src/Kiota.Builder/Refiners/CSharpRefiner.cs index 5e36de1890..2a78396e7d 100644 --- a/src/Kiota.Builder/Refiners/CSharpRefiner.cs +++ b/src/Kiota.Builder/Refiners/CSharpRefiner.cs @@ -171,7 +171,7 @@ protected static void MakeEnumPropertiesNullable(CodeElement currentElement) new (static x => x is CodeClass @class && @class.IsOfKind(CodeClassKind.RequestBuilder), "System.Threading.Tasks", "Task"), new (static x => x is CodeClass @class && @class.IsOfKind(CodeClassKind.Model, CodeClassKind.RequestBuilder), - "System.Linq", "Enumerable"), + ExtensionsNamespaceName, "Enumerable"), new (static x => x is CodeMethod method && method.IsOfKind(CodeMethodKind.ClientConstructor) && method.Parameters.Any(y => y.IsOfKind(CodeParameterKind.BackingStore)), StoreNamespaceName, "IBackingStoreFactory", "IBackingStoreFactorySingleton"), diff --git a/src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs index 796e6a91ac..ead9a4484b 100644 --- a/src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs @@ -10,8 +10,8 @@ public class CodeMethodWriter : BaseElementWriter(){collectionMethod}"; else if (currentType.TypeDefinition is CodeEnum) @@ -407,7 +407,7 @@ protected void WriteRequestExecutorBody(CodeMethod codeElement, RequestParams re }; writer.WriteLine($"{prefix}await RequestAdapter.{GetSendRequestMethodName(isVoid, codeElement, codeElement.ReturnType)}(requestInfo{returnTypeFactory}, {errorMappingVarName}, cancellationToken).ConfigureAwait(false);"); if (codeElement.ReturnType.IsCollection) - writer.WriteLine("return collectionResult?.ToList();"); + writer.WriteLine("return collectionResult?.AsList();"); } private const string RequestInfoVarName = "requestInfo"; private void WriteRequestGeneratorBody(CodeMethod codeElement, RequestParams requestParams, CodeClass currentClass, LanguageWriter writer) diff --git a/tests/Kiota.Builder.Tests/Writers/CSharp/CodeMethodWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/CSharp/CodeMethodWriterTests.cs index 2fe8182ed3..17fb96c17a 100644 --- a/tests/Kiota.Builder.Tests/Writers/CSharp/CodeMethodWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/CSharp/CodeMethodWriterTests.cs @@ -542,7 +542,7 @@ public void WritesRequestExecutorBodyForCollection() Assert.Contains("var errorMapping = new Dictionary>", result); Assert.Contains("{ \"4XX\", Error4XX.CreateFromDiscriminatorValue },", result); Assert.Contains("SendCollectionAsync", result); - Assert.Contains("return collectionResult?.ToList()", result); + Assert.Contains("return collectionResult?.AsList()", result); Assert.Contains($"{ReturnTypeName}.CreateFromDiscriminatorValue", result); AssertExtensions.CurlyBracesAreClosed(result, 1); } @@ -592,7 +592,7 @@ public void WritesModelFactoryBodyForUnionModels() Assert.Contains("ComplexType1Value = new ComplexType1()", result); Assert.Contains("else if(parseNode.GetStringValue() is string stringValueValue)", result); Assert.Contains("StringValue = stringValueValue", result); - Assert.Contains("parseNode.GetCollectionOfObjectValues(ComplexType2.CreateFromDiscriminatorValue)?.ToList() is List complexType2ValueValue", result); + Assert.Contains("parseNode.GetCollectionOfObjectValues(ComplexType2.CreateFromDiscriminatorValue)?.AsList() is List complexType2ValueValue", result); Assert.Contains("ComplexType2Value = complexType2ValueValue", result); Assert.Contains("return result", result); AssertExtensions.Before("GetStringValue() is string stringValueValue", "GetCollectionOfObjectValues", result); @@ -631,7 +631,7 @@ public void WritesModelFactoryBodyForIntersectionModels() Assert.DoesNotContain("if(\"#kiota.complexType1\".Equals(mappingValue, StringComparison.OrdinalIgnoreCase))", result); Assert.Contains("if(parseNode.GetStringValue() is string stringValueValue)", result); Assert.Contains("StringValue = stringValueValue", result); - Assert.Contains("parseNode.GetCollectionOfObjectValues(ComplexType2.CreateFromDiscriminatorValue)?.ToList() is List complexType2ValueValue", result); + Assert.Contains("parseNode.GetCollectionOfObjectValues(ComplexType2.CreateFromDiscriminatorValue)?.AsList() is List complexType2ValueValue", result); Assert.Contains("ComplexType2Value = complexType2ValueValue", result); Assert.Contains("ComplexType1Value = new ComplexType1()", result); Assert.Contains("return result", result);