mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-08 20:45:51 +00:00
Add .net 4.5 compatibility shim classes
Implemented some of the interfaces and classes we use in our .NET 4.5 version.
This commit is contained in:
@@ -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<TKey, TValue> : IReadOnlyCollection<KeyValuePair<TKey, TValue>>
|
||||
{
|
||||
bool ContainsKey(TKey key);
|
||||
bool TryGetValue(TKey key, out TValue value);
|
||||
|
||||
TValue this[TKey key] { get; }
|
||||
IEnumerable<TKey> Keys { get; }
|
||||
IEnumerable<TValue> Values { get; }
|
||||
}
|
||||
|
||||
public interface IReadOnlyCollection<out T> : IEnumerable<T>
|
||||
{
|
||||
int Count { get; }
|
||||
}
|
||||
|
||||
public class ReadOnlyCollection<TItem> : IReadOnlyCollection<TItem>
|
||||
{
|
||||
readonly List<TItem> _source;
|
||||
|
||||
public ReadOnlyCollection(IEnumerable<TItem> source)
|
||||
{
|
||||
_source = new List<TItem>(source);
|
||||
}
|
||||
|
||||
public IEnumerator<TItem> 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<TKey, TValue> : IReadOnlyDictionary<TKey, TValue>
|
||||
{
|
||||
readonly IDictionary<TKey, TValue> _source;
|
||||
|
||||
public ReadOnlyDictionary(IDictionary<TKey, TValue> source)
|
||||
{
|
||||
_source = new Dictionary<TKey, TValue>(source);
|
||||
}
|
||||
|
||||
public IEnumerator<KeyValuePair<TKey, TValue>> 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<TKey> Keys
|
||||
{
|
||||
get { return _source.Keys; }
|
||||
}
|
||||
|
||||
public IEnumerable<TValue> Values
|
||||
{
|
||||
get { return _source.Values; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user