Skip to content

Commit

Permalink
Improvements to SafeDictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisg32 committed Nov 15, 2017
1 parent 0903262 commit af06297
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Commons/Collections/SafeDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,23 @@ namespace CG.Commons.Collections
/// <typeparam name="TValue"></typeparam>
public class SafeDictionary<TKey, TValue> : IDictionary<TKey, TValue>
{
private readonly Dictionary<TKey, TValue> _data = new Dictionary<TKey, TValue>();
private readonly Dictionary<TKey, TValue> _data;

public TValue DefaultValue { get; }

/// <param name="defaultValue">The default value that will be returned when a key is not found.</param>
public SafeDictionary(TValue defaultValue = default(TValue))
{
DefaultValue = defaultValue;
_data = new Dictionary<TKey, TValue>();
}

/// <param name="dictionary"></param>
/// <param name="defaultValue">The default value that will be returned when a key is not found.</param>
public SafeDictionary(Dictionary<TKey, TValue> dictionary, TValue defaultValue = default(TValue))
{
DefaultValue = defaultValue;
_data = dictionary;
}

public TValue this[TKey key]
Expand Down

0 comments on commit af06297

Please sign in to comment.