pulumi/sdk/dotnet/Pulumi/Serialization/Rpc.cs
Fraser Waters 636f2c9a73 fixes
2021-11-12 18:22:42 +00:00

33 lines
1.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using Google.Protobuf.WellKnownTypes;
namespace Pulumi.Serialization
{
public static class Rpc {
public static ImmutableDictionary<string, object?> DeserialiseProperties(Struct properties)
{
var output = Deserializer.Deserialize(Value.ForStruct(properties));
if (!output.IsKnown || output.IsSecret)
{
throw new Exception("Deserialize of a Struct should always be known and not secret!");
}
var result = output.Value as ImmutableDictionary<string, object?>;
if (result == null)
{
throw new Exception("Deserialize of a Struct should always return an ImmutableDictionary!");
}
return result;
}
public static Struct SerialiseProperties(IDictionary<string, object?> properties)
{
var dictionary = ImmutableDictionary.CreateRange(properties);
return Serializer.CreateStruct(dictionary);
}
}
}