pulumi/sdk/dotnet/Pulumi/Core/InputUnion.cs
Justin Van Patten 877d296c5c [sdk/dotnet] Avoid eager conversion to Output<T> in Input<T>
This changes `Input<T>`, `InputList<T>`, `InputMap<V>`, and `InputUnion<T0, T1>` to no longer eagerly convert plain values to `Output<T>`.
2021-11-15 08:44:58 -08:00

43 lines
1.3 KiB
C#

// Copyright 2016-2021, Pulumi Corporation
namespace Pulumi
{
/// <summary>
/// Represents an <see cref="Input{T}"/> value that can be one of two different types. For
/// example, it might potentially be an <see cref="int"/> some of the time or a <see
/// cref="string"/> in other cases.
/// </summary>
public sealed class InputUnion<T0, T1> : Input<Union<T0, T1>>
{
public InputUnion() : this(default(Union<T0, T1>))
{
}
private InputUnion(Union<T0, T1> oneOf)
: base(oneOf)
{
}
private InputUnion(Output<Union<T0, T1>> oneOf)
: base(oneOf)
{
}
#region common conversions
public static implicit operator InputUnion<T0, T1>(T0 value)
=> new InputUnion<T0, T1>(Union<T0, T1>.FromT0(value));
public static implicit operator InputUnion<T0, T1>(T1 value)
=> new InputUnion<T0, T1>(Union<T0, T1>.FromT1(value));
public static implicit operator InputUnion<T0, T1>(Output<T0> value)
=> new InputUnion<T0, T1>(value.Apply(Union<T0, T1>.FromT0));
public static implicit operator InputUnion<T0, T1>(Output<T1> value)
=> new InputUnion<T0, T1>(value.Apply(Union<T0, T1>.FromT1));
#endregion
}
}