2020-12-05 11:12:55 +01:00
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
2020-03-28 20:54:10 +01:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
namespace Umbraco.Cms.Tests.Common.Builders;
|
|
|
|
|
|
|
|
|
|
public class GenericDictionaryBuilder<TBuilder, TKey, TValue>
|
|
|
|
|
: ChildBuilderBase<TBuilder, IDictionary<TKey, TValue>>
|
2020-03-28 20:54:10 +01:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
private readonly IDictionary<TKey, TValue> _dictionary;
|
2020-03-28 20:54:10 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public GenericDictionaryBuilder(TBuilder parentBuilder)
|
|
|
|
|
: base(parentBuilder) => _dictionary = new Dictionary<TKey, TValue>();
|
2020-03-28 20:54:10 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public override IDictionary<TKey, TValue> Build() => _dictionary == null
|
|
|
|
|
? new Dictionary<TKey, TValue>()
|
|
|
|
|
: new Dictionary<TKey, TValue>(_dictionary);
|
2020-03-28 20:54:10 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
public GenericDictionaryBuilder<TBuilder, TKey, TValue> WithKeyValue(TKey key, TValue value)
|
|
|
|
|
{
|
|
|
|
|
_dictionary.Add(key, value);
|
|
|
|
|
return this;
|
2020-03-28 20:54:10 +01:00
|
|
|
}
|
|
|
|
|
}
|