Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove LINQ from generated code #4823

Merged
merged 7 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion it/csharp/dotnet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
<Compile Remove="basic\**" />
</ItemGroup>

</Project>
</Project>
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Refiners/CSharpRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
6 changes: 3 additions & 3 deletions src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public class CodeMethodWriter : BaseElementWriter<CodeMethod, CSharpConventionSe
{
public CodeMethodWriter(CSharpConventionService conventionService) : base(conventionService)
{

}

public override void WriteCodeElement(CodeMethod codeElement, LanguageWriter writer)
{
ArgumentNullException.ThrowIfNull(codeElement);
Expand Down Expand Up @@ -350,7 +350,7 @@ private string GetDeserializationMethodName(CodeTypeBase propType, CodeMethod me
{
if (isCollection)
{
var collectionMethod = propType.IsArray ? "?.ToArray()" : "?.ToList()";
var collectionMethod = propType.IsArray ? "?.AsArray()" : "?.AsList()";
if (currentType.TypeDefinition == null)
return $"GetCollectionOfPrimitiveValues<{propertyType}>(){collectionMethod}";
else if (currentType.TypeDefinition is CodeEnum)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ public void WritesRequestExecutorBodyForCollection()
Assert.Contains("var errorMapping = new Dictionary<string, ParsableFactory<IParsable>>", 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);
}
Expand Down Expand Up @@ -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>(ComplexType2.CreateFromDiscriminatorValue)?.ToList() is List<ComplexType2> complexType2ValueValue", result);
Assert.Contains("parseNode.GetCollectionOfObjectValues<ComplexType2>(ComplexType2.CreateFromDiscriminatorValue)?.AsList() is List<ComplexType2> complexType2ValueValue", result);
Assert.Contains("ComplexType2Value = complexType2ValueValue", result);
Assert.Contains("return result", result);
AssertExtensions.Before("GetStringValue() is string stringValueValue", "GetCollectionOfObjectValues<ComplexType2>", result);
Expand Down Expand Up @@ -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>(ComplexType2.CreateFromDiscriminatorValue)?.ToList() is List<ComplexType2> complexType2ValueValue", result);
Assert.Contains("parseNode.GetCollectionOfObjectValues<ComplexType2>(ComplexType2.CreateFromDiscriminatorValue)?.AsList() is List<ComplexType2> complexType2ValueValue", result);
Assert.Contains("ComplexType2Value = complexType2ValueValue", result);
Assert.Contains("ComplexType1Value = new ComplexType1()", result);
Assert.Contains("return result", result);
Expand Down
Loading