Is it possible to cast the result of a LINQ Enumer...
# dotnet
b
Is it possible to cast the result of a LINQ Enumerable.Select 'System.Collections.Generic.IEnumerable<System.Collections.Generic.IEnumerable<Pulumi.AzureNative.Network.Inputs.SecurityRuleArgs>>' to 'Pulumi.InputList<Pulumi.AzureNative.Network.Inputs.SecurityRuleArgs>' ? All the values come from directly from a Pulumi.dev.yaml none are Outputs
t
Yes, you’d need to flatten the collection, e.g. with
SelectMany
, I think.
b
Thank you, I'll try that. Is there a docs you're aware of that covers this?
t
Not sure… if you have a repro snippet, I can take a look.
b
from the docs --> Implicit(T[] to InputList<T>) so applying a .ToArray() to the result SecurityRules = (_rules.Select(r => MapSecurityRules (r))).ToArray(), worked‼️
t
Yes, you can assign a collection to InputList
w
You'll still want to flatten first with
SelectMany
?
b
Sean, do you have an example? Why would I "flatten" my yaml?
w
You have
IEnumerable<IEnumerable<SecurityRuleArgs>>
presumably from inner
MapSecurityRules
, so to flatten use:
Copy code
SecurityRules = _rules.SelectMany(rule => MapSecurityRules(rule)).ToArray() // or ToImmutableArray()
then if I read that correctly you should be able to use method group syntax:
Copy code
SecurityRules = _rules.SelectMany(MapSecurityRules).ToArray() // or ToImmutableArray()
You flatten it to unroll the inner enumerable into the outer enumerable, if that makes sense. i.e. effectively this converts
IEnumerable<IEnumerable<SecurityRuleArgs>>
to
IEnumerable<SecurityRuleArgs>
b
Excellent! thank you Sean