Created
March 10, 2017 14:45
-
-
Save brettsam/baf21619b280912159b4178650294fcd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class LogValueCollection : IReadOnlyList<KeyValuePair<string, object>> | |
{ | |
private FormattedLogValues _formatter; | |
private IReadOnlyList<KeyValuePair<string, object>> _additionalValues; | |
public LogValueCollection(string format, object[] formatValues, IReadOnlyDictionary<string, object> additionalValues) | |
{ | |
_formatter = new FormattedLogValues(format, formatValues); | |
_additionalValues = additionalValues.ToList(); | |
} | |
public int Count => _formatter.Count + _additionalValues.Count; | |
public KeyValuePair<string, object> this[int index] | |
{ | |
get | |
{ | |
if (index < 0 || index >= Count) | |
{ | |
throw new IndexOutOfRangeException(nameof(index)); | |
} | |
if (index < _additionalValues.Count) | |
{ | |
// if the index is lower, return the value from _additionalValues | |
return _additionalValues[index]; | |
} | |
else | |
{ | |
// if there are no more additionalValues, return from _formatter | |
return _formatter[index - _additionalValues.Count]; | |
} | |
} | |
} | |
public IEnumerator<KeyValuePair<string, object>> GetEnumerator() | |
{ | |
for (int i = 0; i < Count; ++i) | |
{ | |
yield return this[i]; | |
} | |
} | |
IEnumerator IEnumerable.GetEnumerator() | |
{ | |
return GetEnumerator(); | |
} | |
public override string ToString() | |
{ | |
return _formatter.ToString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment