diff --git a/Octokit/Helpers/Net45CompatibilityShim.cs b/Octokit/Helpers/Net45CompatibilityShim.cs new file mode 100644 index 00000000..acb99bfd --- /dev/null +++ b/Octokit/Helpers/Net45CompatibilityShim.cs @@ -0,0 +1,103 @@ +// ---------------------------------------------------- +// THIS WHOLE File CAN GO AWAY WHEN WE TARGET 4.5 ONLY +// ---------------------------------------------------- +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace Octokit +{ + [SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")] + [SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix")] + public interface IReadOnlyDictionary : IReadOnlyCollection> + { + bool ContainsKey(TKey key); + bool TryGetValue(TKey key, out TValue value); + + TValue this[TKey key] { get; } + IEnumerable Keys { get; } + IEnumerable Values { get; } + } + + public interface IReadOnlyCollection : IEnumerable + { + int Count { get; } + } + + public class ReadOnlyCollection : IReadOnlyCollection + { + readonly List _source; + + public ReadOnlyCollection(IEnumerable source) + { + _source = new List(source); + } + + public IEnumerator GetEnumerator() + { + return _source.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public int Count + { + get { return _source.Count; } + } + } + + [SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")] + [SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix")] + public class ReadOnlyDictionary : IReadOnlyDictionary + { + readonly IDictionary _source; + + public ReadOnlyDictionary(IDictionary source) + { + _source = new Dictionary(source); + } + + public IEnumerator> GetEnumerator() + { + return _source.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public int Count + { + get { return _source.Count; } + } + + public bool ContainsKey(TKey key) + { + return _source.ContainsKey(key); + } + + public bool TryGetValue(TKey key, out TValue value) + { + return _source.TryGetValue(key, out value); + } + + public TValue this[TKey key] + { + get { return _source[key]; } + } + + public IEnumerable Keys + { + get { return _source.Keys; } + } + + public IEnumerable Values + { + get { return _source.Values; } + } + } +}