From e8b5a356821652462abedb254d3c3649ff3a5e22 Mon Sep 17 00:00:00 2001 From: Hamza Assyad Date: Fri, 9 Aug 2019 11:48:30 -0700 Subject: [PATCH] feat(dotnet): handling optional and variadic parameters (#680) Handling optional and variadic parameters in .NET Emits the =null or params[] keywords when required in constructors or methods. Ran pack.sh in the CDK with this change, and the S3 construct now looks better: **Optionals:** `public Bucket(Amazon.CDK.Construct scope, string id, Amazon.CDK.AWS.S3.IBucketProps props = null): base(new DeputyProps(new object[]{scope, id, props})) { } ` Making the C# call look like: ` var bucket = new Bucket(this, "bucketName");` Rather than ` var bucket = new Bucket(this, "bucketName", null);` **Variadic:** Tested with null values, empty array, one value array, multiple values array. ``` // Array with no value in constructor params var variadicClassNoParams = new VariadicMethod(); // Array with null value in constructor params var variadicClassNullParams = new VariadicMethod(null); // Array with one value in constructor params var variadicClassOneParam = new VariadicMethod(1); // Array with multiple values in constructor params var variadicClassMultipleParams = new VariadicMethod(1, 2, 3, 4); ``` Fixes #153 Fixes #210 --- .../ComplianceTests.cs | 51 +++++++++++++++++++ .../Amazon.JSII.Runtime/Deputy/DeputyBase.cs | 32 +++++++++++- .../lib/targets/dotnet/dotnetgenerator.ts | 51 +++++++++++-------- .../Tests/CalculatorNamespace/Calculator.cs | 2 +- .../Tests/CalculatorNamespace/DataRenderer.cs | 2 +- .../DefaultedConstructorArgument.cs | 2 +- .../CalculatorNamespace/DeprecatedClass.cs | 2 +- .../DoNotRecognizeAnyAsOptional.cs | 2 +- .../CalculatorNamespace/DocumentedClass.cs | 2 +- .../DontComplainAboutVariadicAfterOptional.cs | 2 +- .../CalculatorNamespace/ExperimentalClass.cs | 2 +- .../IIInterfaceWithOptionalMethodArguments.cs | 2 +- ...terfaceWithOptionalMethodArgumentsProxy.cs | 2 +- .../NullShouldBeTreatedAsUndefined.cs | 4 +- .../OptionalConstructorArgument.cs | 2 +- .../OptionalStructConsumer.cs | 2 +- .../RuntimeTypeChecking.cs | 6 +-- .../Tests/CalculatorNamespace/StableClass.cs | 2 +- .../CalculatorNamespace/StructPassing.cs | 2 +- .../CalculatorNamespace/VariadicMethod.cs | 4 +- .../WithPrivatePropertyInConstructor.cs | 2 +- 21 files changed, 134 insertions(+), 44 deletions(-) diff --git a/packages/jsii-dotnet-runtime-test/test/Amazon.JSII.Runtime.IntegrationTests/ComplianceTests.cs b/packages/jsii-dotnet-runtime-test/test/Amazon.JSII.Runtime.IntegrationTests/ComplianceTests.cs index be14ff0df7..255586e7cd 100644 --- a/packages/jsii-dotnet-runtime-test/test/Amazon.JSII.Runtime.IntegrationTests/ComplianceTests.cs +++ b/packages/jsii-dotnet-runtime-test/test/Amazon.JSII.Runtime.IntegrationTests/ComplianceTests.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using Amazon.JSII.Runtime.Deputy; using Amazon.JSII.Tests.CalculatorNamespace; using CompositeOperation = Amazon.JSII.Tests.CalculatorNamespace.composition.CompositeOperation; @@ -861,6 +862,56 @@ public void NullShouldBeTreatedAsUndefined() obj.VerifyPropertyIsUndefined(); } + [Fact(DisplayName = Prefix + nameof(OptionalAndVariadicArgumentsTest))] + public void OptionalAndVariadicArgumentsTest() + { + // ctor + var objWithOptionalProvided = new NullShouldBeTreatedAsUndefined("param1", null); + var objWithoutOptionalProvided = new NullShouldBeTreatedAsUndefined("param1"); + + // method argument called with null value + objWithoutOptionalProvided.GiveMeUndefined(null); + + // method argument called without null value + objWithoutOptionalProvided.GiveMeUndefined(); + + // Array with no value in constructor params + var variadicClassNoParams = new VariadicMethod(); + + // Array with null value in constructor params + var variadicClassNullParams = new VariadicMethod(null); + + // Array with one value in constructor params + var variadicClassOneParam = new VariadicMethod(1); + + // Array with multiple values in constructor params + var variadicClassMultipleParams = new VariadicMethod(1, 2, 3, 4); + + // Variadic parameter with null passed + variadicClassNoParams.AsArray(Double.MinValue, null); + + // Variadic parameter with default value used + variadicClassNoParams.AsArray(Double.MinValue); + + var list = new List(); + + // Variadic parameter with array with no value + variadicClassNoParams.AsArray(Double.MinValue, list.ToArray()); + + // Variadic parameter with array with one value + list.Add(1d); + variadicClassNoParams.AsArray(Double.MinValue, list.ToArray()); + + // Variadic parameter with array with multiple value + list.Add(2d); + list.Add(3d); + list.Add(4d); + list.Add(5d); + list.Add(6d); + + variadicClassNoParams.AsArray(Double.MinValue, list.ToArray()); + } + [Fact(DisplayName = Prefix + nameof(JsiiAgent))] public void JsiiAgent() { diff --git a/packages/jsii-dotnet-runtime/src/Amazon.JSII.Runtime/Deputy/DeputyBase.cs b/packages/jsii-dotnet-runtime/src/Amazon.JSII.Runtime/Deputy/DeputyBase.cs index c69082b0b6..95bc47cdb3 100644 --- a/packages/jsii-dotnet-runtime/src/Amazon.JSII.Runtime/Deputy/DeputyBase.cs +++ b/packages/jsii-dotnet-runtime/src/Amazon.JSII.Runtime/Deputy/DeputyBase.cs @@ -321,10 +321,40 @@ static object[] ConvertArguments(Parameter[] parameters, params object[] argumen throw new ArgumentException("Arguments do not match method parameters", nameof(arguments)); } + var cleanedArgs = new List(arguments); + var cleanedParams = new List(parameters); + + // Handling variadic parameters (null array, empty array, one value array, n values array..) + if (parameters.Length > 0 && parameters.Last().IsVariadic) + { + // Last parameter is variadic, let's explode the .NET attributes + Array variadicValues = arguments.Last() as Array; + + // We remove the last argument (the variadic array); + cleanedArgs.RemoveAt(cleanedArgs.Count - 1); + + // A null value could be passed as a params + if (variadicValues != null) + { + // We save the last parameter to backfill the parameters list + var lastParameter = cleanedParams.Last(); + + for (int i = 0; i < variadicValues.Length; i++) + { + // Backfill the arguments + cleanedArgs.Add(variadicValues.GetValue(i)); + + // Backfill the parameters if necessary, for a 1:1 mirror with the cleanedArgs + if (cleanedArgs.Count != cleanedParams.Count) + cleanedParams.Add(lastParameter); + } + } + } + IFrameworkToJsiiConverter converter = serviceProvider.GetRequiredService(); IReferenceMap referenceMap = serviceProvider.GetRequiredService(); - return parameters.Zip(arguments, (parameter, frameworkArgument) => + return cleanedParams.Zip(cleanedArgs, (parameter, frameworkArgument) => { if (!converter.TryConvert(parameter, referenceMap, frameworkArgument, out object jsiiArgument)) { diff --git a/packages/jsii-pacmak/lib/targets/dotnet/dotnetgenerator.ts b/packages/jsii-pacmak/lib/targets/dotnet/dotnetgenerator.ts index b0be62acc5..390e356b4e 100644 --- a/packages/jsii-pacmak/lib/targets/dotnet/dotnetgenerator.ts +++ b/packages/jsii-pacmak/lib/targets/dotnet/dotnetgenerator.ts @@ -229,9 +229,6 @@ export class DotNetGenerator extends Generator { this.code.openBlock(`public${inner}${absPrefix} class ${className}${implementsExpr}`); // Compute the class parameters - // TODO: add the support for optional parameters - // Not achievable as of today and not supported by the current generator - // https://github.com/awslabs/jsii/issues/210 let parametersDefinition = ''; let parametersBase = ''; const initializer = cls.initializer; @@ -239,16 +236,13 @@ export class DotNetGenerator extends Generator { this.dotnetDocGenerator.emitDocs(initializer); this.dotnetRuntimeGenerator.emitDeprecatedAttributeIfNecessary(initializer); if (initializer.parameters) { + parametersDefinition = this.renderParametersString(initializer.parameters); for (const p of initializer.parameters) { - const pType = this.typeresolver.toDotNetType(p.type); - const isOptionalPrimitive = this.isOptionalPrimitive(p) ? '?' : ''; - if (parametersDefinition !== '') { - parametersDefinition += ', '; + parametersBase += `${this.nameutils.convertParameterName(p.name)}`; + // If this is not the last parameter, append , + if (initializer.parameters.indexOf(p) !== initializer.parameters.length - 1) { parametersBase += ', '; } - parametersDefinition += `${pType}${isOptionalPrimitive} ${this.nameutils.convertParameterName(p.name)}`; - parametersBase += `${this.nameutils.convertParameterName(p.name)}`; - } } @@ -443,18 +437,34 @@ export class DotNetGenerator extends Generator { } } - // TODO: I uncovered an issue with optional parameters and ordering them - // They are currently not supported by the generator. - // In C#, optional parameters need to be declared after required parameters - // We could make changes to the parameters ordering in the jsii model to support them - // But then an optional parameter becoming non optional would create a mess - // https://github.com/awslabs/jsii/issues/210 + /** + * Renders method parameters string + */ private renderMethodParameters(method: spec.Method): string { + return this.renderParametersString(method.parameters); + } + + /** + * Renders parameters string for methods or constructors + */ + private renderParametersString(parameters: spec.Parameter[] | undefined): string { const params = []; - if (method.parameters) { - for (const p of method.parameters) { - const isOptionalPrimitive = this.isOptionalPrimitive(p) ? '?' : ''; - const st = `${this.typeresolver.toDotNetType(p.type)}${isOptionalPrimitive} ${this.nameutils.convertParameterName(p.name)}`; + if (parameters) { + for (const p of parameters) { + let optionalPrimitive = ''; + let optionalKeyword = ''; + let type = this.typeresolver.toDotNetType(p.type); + if (p.optional) { + optionalKeyword = ' = null'; + if (this.isOptionalPrimitive(p)) { + optionalPrimitive = '?'; + + } + } else if (p.variadic) { + type = `params ${type}[]`; + } + const st = + `${type}${optionalPrimitive} ${this.nameutils.convertParameterName(p.name)}${optionalKeyword}`; params.push(st); } } @@ -637,7 +647,6 @@ export class DotNetGenerator extends Generator { let isVirtualKeyWord = ''; // If the prop parent is a class if (cls.kind === spec.TypeKind.Class) { - const implementedInBase = this.isMemberDefinedOnAncestor(cls as spec.ClassType, prop); if (implementedInBase || datatype || proxy) { // Override if the property is in a datatype or proxy class or declared in a parent class diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/Calculator.cs b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/Calculator.cs index 945d41773a..3b38368237 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/Calculator.cs +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/Calculator.cs @@ -14,7 +14,7 @@ public class Calculator : Amazon.JSII.Tests.CalculatorNamespace.composition.Comp /// /// stability: Experimental /// - public Calculator(Amazon.JSII.Tests.CalculatorNamespace.ICalculatorProps props): base(new DeputyProps(new object[]{props})) + public Calculator(Amazon.JSII.Tests.CalculatorNamespace.ICalculatorProps props = null): base(new DeputyProps(new object[]{props})) { } diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/DataRenderer.cs b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/DataRenderer.cs index f0d0cfc113..a3e0b55e82 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/DataRenderer.cs +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/DataRenderer.cs @@ -28,7 +28,7 @@ protected DataRenderer(DeputyProps props): base(props) /// stability: Experimental /// [JsiiMethod(name: "render", returnsJson: "{\"type\":{\"primitive\":\"string\"}}", parametersJson: "[{\"name\":\"data\",\"optional\":true,\"type\":{\"fqn\":\"@scope/jsii-calc-lib.MyFirstStruct\"}}]")] - public virtual string Render(Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.IMyFirstStruct data) + public virtual string Render(Amazon.JSII.Tests.CalculatorNamespace.LibNamespace.IMyFirstStruct data = null) { return InvokeInstanceMethod(new object[]{data}); } diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/DefaultedConstructorArgument.cs b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/DefaultedConstructorArgument.cs index 28648ca6e9..15798beccd 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/DefaultedConstructorArgument.cs +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/DefaultedConstructorArgument.cs @@ -11,7 +11,7 @@ public class DefaultedConstructorArgument : DeputyBase /// /// stability: Experimental /// - public DefaultedConstructorArgument(double? arg1, string arg2, System.DateTime? arg3): base(new DeputyProps(new object[]{arg1, arg2, arg3})) + public DefaultedConstructorArgument(double? arg1 = null, string arg2 = null, System.DateTime? arg3 = null): base(new DeputyProps(new object[]{arg1, arg2, arg3})) { } diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/DeprecatedClass.cs b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/DeprecatedClass.cs index fc8f8e9550..eb025e0de6 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/DeprecatedClass.cs +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/DeprecatedClass.cs @@ -13,7 +13,7 @@ public class DeprecatedClass : DeputyBase /// stability: Deprecated /// [System.Obsolete("this constructor is \"just\" okay")] - public DeprecatedClass(string readonlyString, double? mutableNumber): base(new DeputyProps(new object[]{readonlyString, mutableNumber})) + public DeprecatedClass(string readonlyString, double? mutableNumber = null): base(new DeputyProps(new object[]{readonlyString, mutableNumber})) { } diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/DoNotRecognizeAnyAsOptional.cs b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/DoNotRecognizeAnyAsOptional.cs index 5558f78b15..102e9dd1df 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/DoNotRecognizeAnyAsOptional.cs +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/DoNotRecognizeAnyAsOptional.cs @@ -25,7 +25,7 @@ protected DoNotRecognizeAnyAsOptional(DeputyProps props): base(props) /// stability: Experimental /// [JsiiMethod(name: "method", parametersJson: "[{\"name\":\"_requiredAny\",\"type\":{\"primitive\":\"any\"}},{\"name\":\"_optionalAny\",\"optional\":true,\"type\":{\"primitive\":\"any\"}},{\"name\":\"_optionalString\",\"optional\":true,\"type\":{\"primitive\":\"string\"}}]")] - public virtual void Method(object requiredAny, object optionalAny, string optionalString) + public virtual void Method(object requiredAny, object optionalAny = null, string optionalString = null) { InvokeInstanceVoidMethod(new object[]{requiredAny, optionalAny, optionalString}); } diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/DocumentedClass.cs b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/DocumentedClass.cs index de3ef71b01..c3ff67d57d 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/DocumentedClass.cs +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/DocumentedClass.cs @@ -36,7 +36,7 @@ protected DocumentedClass(DeputyProps props): base(props) /// stability: Stable /// [JsiiMethod(name: "greet", returnsJson: "{\"type\":{\"primitive\":\"number\"}}", parametersJson: "[{\"docs\":{\"summary\":\"The person to be greeted.\"},\"name\":\"greetee\",\"optional\":true,\"type\":{\"fqn\":\"jsii-calc.Greetee\"}}]")] - public virtual double Greet(Amazon.JSII.Tests.CalculatorNamespace.IGreetee greetee) + public virtual double Greet(Amazon.JSII.Tests.CalculatorNamespace.IGreetee greetee = null) { return InvokeInstanceMethod(new object[]{greetee}); } diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/DontComplainAboutVariadicAfterOptional.cs b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/DontComplainAboutVariadicAfterOptional.cs index 8e3f212f97..56ed922b60 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/DontComplainAboutVariadicAfterOptional.cs +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/DontComplainAboutVariadicAfterOptional.cs @@ -24,7 +24,7 @@ protected DontComplainAboutVariadicAfterOptional(DeputyProps props): base(props) /// stability: Experimental /// [JsiiMethod(name: "optionalAndVariadic", returnsJson: "{\"type\":{\"primitive\":\"string\"}}", parametersJson: "[{\"name\":\"optional\",\"optional\":true,\"type\":{\"primitive\":\"string\"}},{\"name\":\"things\",\"type\":{\"primitive\":\"string\"},\"variadic\":true}]")] - public virtual string OptionalAndVariadic(string optional, string things) + public virtual string OptionalAndVariadic(string optional = null, params string[] things) { return InvokeInstanceMethod(new object[]{optional, things}); } diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/ExperimentalClass.cs b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/ExperimentalClass.cs index 3e56dc5010..47db920320 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/ExperimentalClass.cs +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/ExperimentalClass.cs @@ -11,7 +11,7 @@ public class ExperimentalClass : DeputyBase /// /// stability: Experimental /// - public ExperimentalClass(string readonlyString, double? mutableNumber): base(new DeputyProps(new object[]{readonlyString, mutableNumber})) + public ExperimentalClass(string readonlyString, double? mutableNumber = null): base(new DeputyProps(new object[]{readonlyString, mutableNumber})) { } diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/IIInterfaceWithOptionalMethodArguments.cs b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/IIInterfaceWithOptionalMethodArguments.cs index 473ffa2500..9418038917 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/IIInterfaceWithOptionalMethodArguments.cs +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/IIInterfaceWithOptionalMethodArguments.cs @@ -13,6 +13,6 @@ public interface IIInterfaceWithOptionalMethodArguments /// stability: Experimental /// [JsiiMethod(name: "hello", parametersJson: "[{\"name\":\"arg1\",\"type\":{\"primitive\":\"string\"}},{\"name\":\"arg2\",\"optional\":true,\"type\":{\"primitive\":\"number\"}}]")] - void Hello(string arg1, double? arg2); + void Hello(string arg1, double? arg2 = null); } } diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/IInterfaceWithOptionalMethodArgumentsProxy.cs b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/IInterfaceWithOptionalMethodArgumentsProxy.cs index 2ca248c312..12a2283996 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/IInterfaceWithOptionalMethodArgumentsProxy.cs +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/IInterfaceWithOptionalMethodArgumentsProxy.cs @@ -17,7 +17,7 @@ private IInterfaceWithOptionalMethodArgumentsProxy(ByRefValue reference): base(r /// stability: Experimental /// [JsiiMethod(name: "hello", parametersJson: "[{\"name\":\"arg1\",\"type\":{\"primitive\":\"string\"}},{\"name\":\"arg2\",\"optional\":true,\"type\":{\"primitive\":\"number\"}}]")] - public void Hello(string arg1, double? arg2) + public void Hello(string arg1, double? arg2 = null) { InvokeInstanceVoidMethod(new object[]{arg1, arg2}); } diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/NullShouldBeTreatedAsUndefined.cs b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/NullShouldBeTreatedAsUndefined.cs index 92f9eb58a0..897d15eda1 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/NullShouldBeTreatedAsUndefined.cs +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/NullShouldBeTreatedAsUndefined.cs @@ -12,7 +12,7 @@ public class NullShouldBeTreatedAsUndefined : DeputyBase /// /// stability: Experimental /// - public NullShouldBeTreatedAsUndefined(string param1, object optional): base(new DeputyProps(new object[]{param1, optional})) + public NullShouldBeTreatedAsUndefined(string param1, object optional = null): base(new DeputyProps(new object[]{param1, optional})) { } @@ -28,7 +28,7 @@ protected NullShouldBeTreatedAsUndefined(DeputyProps props): base(props) /// stability: Experimental /// [JsiiMethod(name: "giveMeUndefined", parametersJson: "[{\"name\":\"value\",\"optional\":true,\"type\":{\"primitive\":\"any\"}}]")] - public virtual void GiveMeUndefined(object @value) + public virtual void GiveMeUndefined(object @value = null) { InvokeInstanceVoidMethod(new object[]{@value}); } diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/OptionalConstructorArgument.cs b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/OptionalConstructorArgument.cs index 6903a14cd7..3cbbc1ac03 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/OptionalConstructorArgument.cs +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/OptionalConstructorArgument.cs @@ -11,7 +11,7 @@ public class OptionalConstructorArgument : DeputyBase /// /// stability: Experimental /// - public OptionalConstructorArgument(double arg1, string arg2, System.DateTime? arg3): base(new DeputyProps(new object[]{arg1, arg2, arg3})) + public OptionalConstructorArgument(double arg1, string arg2, System.DateTime? arg3 = null): base(new DeputyProps(new object[]{arg1, arg2, arg3})) { } diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/OptionalStructConsumer.cs b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/OptionalStructConsumer.cs index 169677ca25..7dac995a47 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/OptionalStructConsumer.cs +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/OptionalStructConsumer.cs @@ -11,7 +11,7 @@ public class OptionalStructConsumer : DeputyBase /// /// stability: Experimental /// - public OptionalStructConsumer(Amazon.JSII.Tests.CalculatorNamespace.IOptionalStruct optionalStruct): base(new DeputyProps(new object[]{optionalStruct})) + public OptionalStructConsumer(Amazon.JSII.Tests.CalculatorNamespace.IOptionalStruct optionalStruct = null): base(new DeputyProps(new object[]{optionalStruct})) { } diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/RuntimeTypeChecking.cs b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/RuntimeTypeChecking.cs index 23fb7ed883..a1a8780628 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/RuntimeTypeChecking.cs +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/RuntimeTypeChecking.cs @@ -24,7 +24,7 @@ protected RuntimeTypeChecking(DeputyProps props): base(props) /// stability: Experimental /// [JsiiMethod(name: "methodWithDefaultedArguments", parametersJson: "[{\"name\":\"arg1\",\"optional\":true,\"type\":{\"primitive\":\"number\"}},{\"name\":\"arg2\",\"optional\":true,\"type\":{\"primitive\":\"string\"}},{\"name\":\"arg3\",\"optional\":true,\"type\":{\"primitive\":\"date\"}}]")] - public virtual void MethodWithDefaultedArguments(double? arg1, string arg2, System.DateTime? arg3) + public virtual void MethodWithDefaultedArguments(double? arg1 = null, string arg2 = null, System.DateTime? arg3 = null) { InvokeInstanceVoidMethod(new object[]{arg1, arg2, arg3}); } @@ -33,7 +33,7 @@ public virtual void MethodWithDefaultedArguments(double? arg1, string arg2, Syst /// stability: Experimental /// [JsiiMethod(name: "methodWithOptionalAnyArgument", parametersJson: "[{\"name\":\"arg\",\"optional\":true,\"type\":{\"primitive\":\"any\"}}]")] - public virtual void MethodWithOptionalAnyArgument(object arg) + public virtual void MethodWithOptionalAnyArgument(object arg = null) { InvokeInstanceVoidMethod(new object[]{arg}); } @@ -43,7 +43,7 @@ public virtual void MethodWithOptionalAnyArgument(object arg) /// stability: Experimental /// [JsiiMethod(name: "methodWithOptionalArguments", parametersJson: "[{\"name\":\"arg1\",\"type\":{\"primitive\":\"number\"}},{\"name\":\"arg2\",\"type\":{\"primitive\":\"string\"}},{\"name\":\"arg3\",\"optional\":true,\"type\":{\"primitive\":\"date\"}}]")] - public virtual void MethodWithOptionalArguments(double arg1, string arg2, System.DateTime? arg3) + public virtual void MethodWithOptionalArguments(double arg1, string arg2, System.DateTime? arg3 = null) { InvokeInstanceVoidMethod(new object[]{arg1, arg2, arg3}); } diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/StableClass.cs b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/StableClass.cs index 86c453692a..eea996a83f 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/StableClass.cs +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/StableClass.cs @@ -11,7 +11,7 @@ public class StableClass : DeputyBase /// /// stability: Stable /// - public StableClass(string readonlyString, double? mutableNumber): base(new DeputyProps(new object[]{readonlyString, mutableNumber})) + public StableClass(string readonlyString, double? mutableNumber = null): base(new DeputyProps(new object[]{readonlyString, mutableNumber})) { } diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/StructPassing.cs b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/StructPassing.cs index 32f792f140..f7674673be 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/StructPassing.cs +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/StructPassing.cs @@ -25,7 +25,7 @@ protected StructPassing(DeputyProps props): base(props) /// stability: External /// [JsiiMethod(name: "howManyVarArgsDidIPass", returnsJson: "{\"type\":{\"primitive\":\"number\"}}", parametersJson: "[{\"name\":\"_positional\",\"type\":{\"primitive\":\"number\"}},{\"name\":\"inputs\",\"type\":{\"fqn\":\"jsii-calc.TopLevelStruct\"},\"variadic\":true}]")] - public static double HowManyVarArgsDidIPass(double positional, Amazon.JSII.Tests.CalculatorNamespace.ITopLevelStruct inputs) + public static double HowManyVarArgsDidIPass(double positional, params Amazon.JSII.Tests.CalculatorNamespace.ITopLevelStruct[] inputs) { return InvokeStaticMethod(typeof(Amazon.JSII.Tests.CalculatorNamespace.StructPassing), new object[]{positional, inputs}); } diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/VariadicMethod.cs b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/VariadicMethod.cs index ef2a10b816..ce2f140d76 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/VariadicMethod.cs +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/VariadicMethod.cs @@ -12,7 +12,7 @@ public class VariadicMethod : DeputyBase /// /// stability: Experimental /// - public VariadicMethod(double prefix): base(new DeputyProps(new object[]{prefix})) + public VariadicMethod(params double[] prefix): base(new DeputyProps(new object[]{prefix})) { } @@ -30,7 +30,7 @@ protected VariadicMethod(DeputyProps props): base(props) /// stability: Experimental /// [JsiiMethod(name: "asArray", returnsJson: "{\"type\":{\"collection\":{\"elementtype\":{\"primitive\":\"number\"},\"kind\":\"array\"}}}", parametersJson: "[{\"docs\":{\"summary\":\"the first element of the array to be returned (after the `prefix` provided at construction time).\"},\"name\":\"first\",\"type\":{\"primitive\":\"number\"}},{\"docs\":{\"summary\":\"other elements to be included in the array.\"},\"name\":\"others\",\"type\":{\"primitive\":\"number\"},\"variadic\":true}]")] - public virtual double[] AsArray(double first, double others) + public virtual double[] AsArray(double first, params double[] others) { return InvokeInstanceMethod(new object[]{first, others}); } diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/WithPrivatePropertyInConstructor.cs b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/WithPrivatePropertyInConstructor.cs index 84d38c1704..0748877d02 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/WithPrivatePropertyInConstructor.cs +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon/JSII/Tests/CalculatorNamespace/WithPrivatePropertyInConstructor.cs @@ -12,7 +12,7 @@ public class WithPrivatePropertyInConstructor : DeputyBase /// /// stability: Experimental /// - public WithPrivatePropertyInConstructor(string privateField): base(new DeputyProps(new object[]{privateField})) + public WithPrivatePropertyInConstructor(string privateField = null): base(new DeputyProps(new object[]{privateField})) { }