You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This might be more involved that just adding the "params" keyword. Consider the following signature:
public void DoSomething(params object[] myParam)
{
}
// ...
object[] foo = // ...
// Because an object[] is also an object, the compiler treats foo as the first element
// of the params array, rather than the params array itself.
DoSomething(foo);
But in this case, there's no ambiguity:
public void DoSomething(params string[] myParam)
{
}
// ...
string[] foo = // ...
// The compiler treats foo as the params array, rather than the first element of the params array.
DoSomething(foo);
This might not matter, since generated code does not include any invocations of the generated methods. Just something to keep in mind.
I guess i'm running into a related issue to this now in 0.29 of the C# CDK
AddActions of the PolicyStatement has the following signature [JsiiMethod("addActions", "{\"type\":{\"fqn\":\"@aws-cdk/aws-iam.PolicyStatement\"}}", "[{\"name\":\"actions\",\"variadic\":true,\"type\":{\"primitive\":\"string\"}}]", false, false)]
But the generated C# method has the following signature, with a string public virtual PolicyStatement AddActions(string actions)
Is there anyway i can create a correct string of a string params, or is this just something that need to be solved in this issue?
This has been an issue for a while. The way I deal with this situation is to create an extension method to get the behavior I want. For my purposes I wanted to add multiple actions via a comma delimited set of actions as a single string, but you could easily go with an IEnumerable<string> instead. The extension method I use is included below. It would be better to teach JSII how to deal with variable number of arguments in C#. Unfortunately I’m slammed on other projects at the moment, or I’d look at contributing something.
--Bonnie
/// <summary>
/// Adds actions to a policy statement from a comma separated list of actions names as part of initializing IAM objects.
/// </summary>
/// <param name="statement">What policy statement</param>
/// <param name="actions">The names of the actions to add</param>
/// <returns></returns>
public static PolicyStatement AddActionsFromString(this PolicyStatement statement, string actions)
{
var policyStatement = statement;
foreach (string action in actions.Split(", "))
{
policyStatement = policyStatement.AddAction(action);
}
return policyStatement;
}
From: Erik Karlsson <[email protected]>
Sent: Thursday, April 25, 2019 6:15 AM
To: awslabs/jsii <[email protected]>
Cc: Feinberg, Bonnie <[email protected]>; Manual <[email protected]>
Subject: Re: [awslabs/jsii] Support variadic parameters for .NET (#153)
I guess i'm running into a related issue to this now in 0.29 of the C# CDK
AddActions of the PolicyStatement has the following signature
[JsiiMethod("addActions", "{\"type\":{\"fqn\":\"@aws-cdk/aws-iam.PolicyStatement\"}}", "[{\"name\":\"actions\",\"variadic\":true,\"type\":{\"primitive\":\"string\"}}]", false, false)]
But the generated C# method has the following signature, with a string
public virtual PolicyStatement AddActions(string actions)
Is there anyway i can create a correct string of a string params, or is this just something that need to be solved in this issue?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub<#153 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AKCL62L6TAIWZTQYUNEVUXTPSGVGDANCNFSM4FOENHGQ>.
This has been an issue for a while. The way I deal with this situation is to create an extension method to get the behavior I want. For my purposes I wanted to add multiple actions via a comma delimited set of actions as a single string, but you could easily go with an IEnumerable instead. The extension method I use is included below. It would be better to teach JSII how to deal with variable number of arguments in C#. Unfortunately I’m slammed on other projects at the moment, or I’d look at contributing something. …
--Bonnie ///
/// Adds actions to a policy statement from a comma separated list of actions names as part of initializing IAM objects. /// /// What policy statement /// The names of the actions to add /// public static PolicyStatement AddActionsFromString(this PolicyStatement statement, string actions) { var policyStatement = statement; foreach (string action in actions.Split(", ")) { policyStatement = policyStatement.AddAction(action); } return policyStatement; } From: Erik Karlsson [email protected] Sent: Thursday, April 25, 2019 6:15 AM To: awslabs/jsii [email protected] Cc: Feinberg, Bonnie [email protected]; Manual [email protected] Subject: Re: [awslabs/jsii] Support variadic parameters for .NET (#153) I guess i'm running into a related issue to this now in 0.29 of the C# CDK AddActions of the PolicyStatement has the following signature [JsiiMethod("addActions", "{"type":{"fqn":"@aws-cdk/aws-iam.PolicyStatement"}}", "[{"name":"actions","variadic":true,"type":{"primitive":"string"}}]", false, false)] But the generated C# method has the following signature, with a string public virtual PolicyStatement AddActions(string actions) Is there anyway i can create a correct string of a string params, or is this just something that need to be solved in this issue? — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub<#153 (comment)>, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AKCL62L6TAIWZTQYUNEVUXTPSGVGDANCNFSM4FOENHGQ.
I tried something similar with a static method and looping over several actions, but then i get the following error in the app.Run() step:
Amazon.JSII.Runtime.JsiiException: 'While synthesizing mimer-ses-15/db-key/Resource: System.ArgumentException: Could not convert value 'System.Collections.Generic.Dictionary`2[System.String,System.Object]' with unrecognized type
Parameter name: value
Only reason i need it is beacuase of a related issue in the new 0.29, aws/aws-cdk#2375
I guess i will have to wait for that, or just create a new statement for every action instead
Activity
McDoit commentedon Apr 25, 2019
I guess i'm running into a related issue to this now in 0.29 of the C# CDK
AddActions of the PolicyStatement has the following signature
[JsiiMethod("addActions", "{\"type\":{\"fqn\":\"@aws-cdk/aws-iam.PolicyStatement\"}}", "[{\"name\":\"actions\",\"variadic\":true,\"type\":{\"primitive\":\"string\"}}]", false, false)]But the generated C# method has the following signature, with a string
public virtual PolicyStatement AddActions(string actions)Is there anyway i can create a correct string of a string params, or is this just something that need to be solved in this issue?
bfeinb commentedon Apr 25, 2019
McDoit commentedon Apr 26, 2019
Thank you @bfeinb
I tried something similar with a static method and looping over several actions, but then i get the following error in the
app.Run()step:Only reason i need it is beacuase of a related issue in the new 0.29, aws/aws-cdk#2375
I guess i will have to wait for that, or just create a new statement for every action instead
feat(dotnet): handling optional and variadic parameters (#680)