diff --git a/src/Kiota.Builder/Refiners/CliRefiner.cs b/src/Kiota.Builder/Refiners/CliRefiner.cs index c579db09f0..ba7a6d5b48 100644 --- a/src/Kiota.Builder/Refiners/CliRefiner.cs +++ b/src/Kiota.Builder/Refiners/CliRefiner.cs @@ -103,37 +103,10 @@ public override Task Refine(CodeNamespace generatedCode, CancellationToken cance RenameDuplicateIndexerNavProperties(generatedCode); // Must be called after the more specific RenameDuplicateIndexerNavProperties RenameMatchingSubsequentNavCommands(generatedCode); - AddArgsParameterToClientConstructor(generatedCode); cancellationToken.ThrowIfCancellationRequested(); CreateCommandBuilders(generatedCode); }, cancellationToken); } - private static void AddArgsParameterToClientConstructor(CodeElement currentElement) - { - if (currentElement is CodeClass currentClass && currentClass.Kind is CodeClassKind.RequestBuilder) - { - var clientConstructor = currentClass.UnorderedMethods.SingleOrDefault(static m => m.Kind is CodeMethodKind.ClientConstructor); - if (clientConstructor is { } m) - { - m.AddParameter(new CodeParameter - { - Name = "args", - Optional = false, - Kind = CodeParameterKind.Custom, - Type = new CodeType - { - Name = "string", - IsExternal = true, - IsNullable = false, - CollectionKind = CodeTypeBase.CodeTypeCollectionKind.Array - } - }); - return; - } - } - - CrawlTree(currentElement, AddArgsParameterToClientConstructor); - } private static void RemoveBackwardCompatibleIndexers(CodeElement currentElement) { //TODO remove for v2 diff --git a/src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs b/src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs index 9852c731a7..45ff66908a 100644 --- a/src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs +++ b/src/Kiota.Builder/Writers/CSharp/CodeMethodWriter.cs @@ -215,8 +215,8 @@ private void WriteRequestBuilderBody(CodeClass parentClass, CodeMethod codeEleme } private static void WriteApiConstructorBody(CodeClass parentClass, CodeMethod method, LanguageWriter writer) { - if (method.Parameters.Any(static p => string.Equals(p.Name, "args", StringComparison.Ordinal))) { - writer.WriteLine("Arguments = args.TakeWhile(static x => !string.IsNullOrEmpty(x) && !x.StartsWith('-')).ToArray();"); + if (parentClass.StartBlock?.Inherits?.Name?.Contains("CliRequestBuilder", StringComparison.Ordinal) == true) { + writer.WriteLine("Arguments = Environment.GetCommandLineArgs().Skip(1).TakeWhile(static x => !string.IsNullOrEmpty(x) && !x.StartsWith('-')).ToArray();"); } if (parentClass.GetPropertyOfKind(CodePropertyKind.RequestAdapter) is not CodeProperty requestAdapterProperty) return; var pathParametersProperty = parentClass.GetPropertyOfKind(CodePropertyKind.PathParameters);