Loading files
8e2d3bacaThis file is pinned to the selected release. Download the original to open it in your design tool.
using Hast.Common.ContractResolvers;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace System.Collections.Generic
{
public static class DictionaryExtensions
{
public static T GetOrAddCustomConfiguration<T>(this IDictionary<string, object> customConfiguration, string key)
where T : new()
{
if (customConfiguration.TryGetValue(key, out object config))
{
// If this is a remote transformation then custom configs won't necessarily be properly deserialized at
// this point, so need to handle them specifically.
if (config is JObject)
{
return ((JObject)config).ToObject<T>(new JsonSerializer { ContractResolver = new PrivateSetterContractResolver() });
}
return (T)config;
}
return (T)(customConfiguration[key] = new T());
}
public static void Deconstruct<TKey, TValue>(this KeyValuePair<TKey, TValue> pair, out TKey key, out TValue value)
{
key = pair.Key;
value = pair.Value;
}
}
}