https://pulumi.com logo
#dotnet
Title
# dotnet
l

little-cartoon-10569

07/26/2021, 5:23 AM
In the third snippet of the example on https://www.pulumi.com/docs/intro/concepts/stack/#stackreferences, the C# code has an apparently-redundant
Apply(v => v.ToString())
. None of the other languages have that. Is it neccessary? If it is, why?
g

green-stone-37839

07/26/2021, 6:12 PM
Yes, it is necessary. In the k8s ProviderArgs, the KubeConfig property is string. With no explicit "ToString" call in the Apply function you'll end up with a kubeConfig type of Output<object> and a compiler error. ``````
w

worried-city-86458

07/26/2021, 6:59 PM
I use the following output extensions:
Copy code
public static class OutputExtensions
{
    public static Output<T> As<T>(this Output<object> output) => output.Apply(x => (T)x);

    public static Output<Resource> AsResource<T>(this Output<T> output) where T : Resource => output.Apply(x => (Resource)x);

    public static Output<T> WhenRun<T>(this Output<T> output, Func<T, Task> func) =>
        !Deployment.Instance.IsDryRun ? output.Apply(async value => { await func(value); return value; }) : output;
}
Then that line becomes:
Copy code
var kubeConfig = cluster.RequireOutput("KubeConfig").As<string>();