Skip to content

Commit

Permalink
Fix usage of nullable for TomlTable (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoofx committed Feb 25, 2022
1 parent 60b7333 commit 909dd77
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/Tomlyn/Model/Accessors/DictionaryDynamicAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private TomlTableAccessor() : base(typeof(string), typeof(object))

public override IEnumerable<KeyValuePair<string, object?>> GetElements(object dictionary)
{
return ((TomlTable)dictionary);
return (IEnumerable<KeyValuePair<string, object?>>)dictionary;
}

public override bool TryGetValue(object dictionary, object key, out object? value)
Expand Down
32 changes: 16 additions & 16 deletions src/Tomlyn/Model/TomlTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Tomlyn.Model
/// <remarks>
/// This object keep the order of the inserted key=values
/// </remarks>
public sealed class TomlTable : TomlObject, IDictionary<string, object?>, ITomlMetadataProvider
public sealed class TomlTable : TomlObject, IDictionary<string, object>, ITomlMetadataProvider
{
private readonly List<KeyValuePair<string, ValueHolder>> _order;
private readonly Dictionary<string, ValueHolder> _map;
Expand All @@ -39,12 +39,12 @@ public TomlTable(bool inline) : base(inline ? ObjectKind.InlineTable : ObjectKin
/// <inheritdoc/>
public TomlPropertiesMetadata? PropertiesMetadata { get; set; }

public IEnumerator<KeyValuePair<string, object?>> GetEnumerator()
public IEnumerator<KeyValuePair<string, object>> GetEnumerator()
{

foreach (var keyPair in _order)
{
yield return new KeyValuePair<string, object?>(keyPair.Key, keyPair.Value.Target);
yield return new KeyValuePair<string, object>(keyPair.Key, keyPair.Value.Target);
}
}

Expand All @@ -53,7 +53,7 @@ IEnumerator IEnumerable.GetEnumerator()
return GetEnumerator();
}

void ICollection<KeyValuePair<string, object?>>.Add(KeyValuePair<string, object?> item)
void ICollection<KeyValuePair<string, object>>.Add(KeyValuePair<string, object> item)
{
Add(item.Key, item.Value);
}
Expand All @@ -64,7 +64,7 @@ public void Clear()
_order.Clear();
}

bool ICollection<KeyValuePair<string, object?>>.Contains(KeyValuePair<string, object?> item)
bool ICollection<KeyValuePair<string, object>>.Contains(KeyValuePair<string, object> item)
{
foreach (var pair in _order)
{
Expand All @@ -77,17 +77,17 @@ public void Clear()
return false;
}

void ICollection<KeyValuePair<string, object?>>.CopyTo(KeyValuePair<string, object?>[] array, int arrayIndex)
void ICollection<KeyValuePair<string, object>>.CopyTo(KeyValuePair<string, object>[] array, int arrayIndex)
{
if (arrayIndex + _order.Count > array.Length) throw new ArgumentOutOfRangeException(nameof(arrayIndex));
for (var i = 0; i < _order.Count; i++)
{
var item = _order[i];
array[i + arrayIndex] = new KeyValuePair<string, object?>(item.Key, item.Value.Target);
array[i + arrayIndex] = new KeyValuePair<string, object>(item.Key, item.Value.Target);
}
}

bool ICollection<KeyValuePair<string, object?>>.Remove(KeyValuePair<string, object?> item)
bool ICollection<KeyValuePair<string, object>>.Remove(KeyValuePair<string, object> item)
{
foreach (var keyPair in _order)
{
Expand All @@ -108,7 +108,7 @@ public void Clear()

public bool IsReadOnly => false;

public void Add(string key, object? value)
public void Add(string key, object value)
{
if (value == null) throw new ArgumentNullException(nameof(value));
var valueHolder = new ValueHolder(value);
Expand Down Expand Up @@ -139,9 +139,9 @@ public bool Remove(string key)
return false;
}

public bool TryGetValue(string key, out object? value)
public bool TryGetValue(string key, out object value)
{
value = null;
value = null!;
if (_map.TryGetValue(key, out var valueHolder))
{
value = valueHolder.Target;
Expand All @@ -151,7 +151,7 @@ public bool TryGetValue(string key, out object? value)
return false;
}

public object? this[string key]
public object this[string key]
{
get => _map[key].Target;
set
Expand Down Expand Up @@ -181,11 +181,11 @@ public ICollection<string> Keys
}
}

public ICollection<object?> Values
public ICollection<object> Values
{
get
{
var list = new List<object?>();
var list = new List<object>();
foreach (var valuePair in _order)
{
list.Add(valuePair.Value.Target);
Expand All @@ -203,12 +203,12 @@ public static TomlTable From(DocumentSyntax documentSyntax)

private class ValueHolder
{
public ValueHolder(object? target)
public ValueHolder(object target)
{
Target = target;
}

public object? Target { get; set; }
public object Target { get; set; }
}
}
}

0 comments on commit 909dd77

Please sign in to comment.