Skip to content

Commit

Permalink
Merge pull request #573 from microsoft/ujjwalchadha/fix-splittablemap
Browse files Browse the repository at this point in the history
Fixed ConstantSplittableMap's Keys and Values to return read only col…
  • Loading branch information
ujjwalchadha committed Nov 10, 2020
2 parents d00974b + ecb5672 commit 183fc48
Show file tree
Hide file tree
Showing 2 changed files with 218 additions and 247 deletions.
233 changes: 109 additions & 124 deletions WinRT.Runtime/Projections/IReadOnlyDictionary.net5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,112 @@ public static void DisposeAbi(IntPtr abi) =>

public static string GetGuidSignature() => GuidGenerator.GetSignature(typeof(IReadOnlyDictionary<K, V>));

private sealed class ReadOnlyDictionaryKeyCollection : global::System.Collections.Generic.IEnumerable<K>
{
private readonly global::System.Collections.Generic.IReadOnlyDictionary<K, V> dictionary;

public ReadOnlyDictionaryKeyCollection(global::System.Collections.Generic.IReadOnlyDictionary<K, V> dictionary)
{
if (dictionary == null)
throw new ArgumentNullException(nameof(dictionary));

this.dictionary = dictionary;
}

public global::System.Collections.Generic.IEnumerator<K> GetEnumerator()
{
return new ReadOnlyDictionaryKeyEnumerator(dictionary);
}
IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => GetEnumerator();

private sealed class ReadOnlyDictionaryKeyEnumerator : global::System.Collections.Generic.IEnumerator<K>
{
private readonly global::System.Collections.Generic.IReadOnlyDictionary<K, V> dictionary;
private global::System.Collections.Generic.IEnumerator<global::System.Collections.Generic.KeyValuePair<K, V>> enumeration;

public ReadOnlyDictionaryKeyEnumerator(global::System.Collections.Generic.IReadOnlyDictionary<K, V> dictionary)
{
if (dictionary == null)
throw new ArgumentNullException(nameof(dictionary));

this.dictionary = dictionary;
enumeration = dictionary.GetEnumerator();
}

void IDisposable.Dispose()
{
enumeration.Dispose();
}

public bool MoveNext()
{
return enumeration.MoveNext();
}

object IEnumerator.Current => Current;

public K Current => enumeration.Current.Key;

public void Reset()
{
enumeration = dictionary.GetEnumerator();
}
}
}

private sealed class ReadOnlyDictionaryValueCollection : global::System.Collections.Generic.IEnumerable<V>
{
private readonly global::System.Collections.Generic.IReadOnlyDictionary<K, V> dictionary;

public ReadOnlyDictionaryValueCollection(global::System.Collections.Generic.IReadOnlyDictionary<K, V> dictionary)
{
if (dictionary == null)
throw new ArgumentNullException(nameof(dictionary));

this.dictionary = dictionary;
}

public global::System.Collections.Generic.IEnumerator<V> GetEnumerator()
{
return new ReadOnlyDictionaryValueEnumerator(dictionary);
}
global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => GetEnumerator();

private sealed class ReadOnlyDictionaryValueEnumerator : global::System.Collections.Generic.IEnumerator<V>
{
private readonly global::System.Collections.Generic.IReadOnlyDictionary<K, V> dictionary;
private global::System.Collections.Generic.IEnumerator<global::System.Collections.Generic.KeyValuePair<K, V>> enumeration;

public ReadOnlyDictionaryValueEnumerator(global::System.Collections.Generic.IReadOnlyDictionary<K, V> dictionary)
{
if (dictionary == null)
throw new ArgumentNullException(nameof(dictionary));

this.dictionary = dictionary;
enumeration = dictionary.GetEnumerator();
}

void IDisposable.Dispose()
{
enumeration.Dispose();
}

public bool MoveNext()
{
return enumeration.MoveNext();
}

object IEnumerator.Current => Current;

public V Current => enumeration.Current.Value;

public void Reset()
{
enumeration = dictionary.GetEnumerator();
}
}
}

public class FromAbiHelper : global::System.Collections.Generic.IReadOnlyDictionary<K, V>
{
private readonly global::Windows.Foundation.Collections.IMapView<K, V> _mapView;
Expand Down Expand Up @@ -149,111 +255,6 @@ private static V Lookup(global::Windows.Foundation.Collections.IMapView<K, V> _t

IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => GetEnumerator();

private sealed class ReadOnlyDictionaryKeyCollection : global::System.Collections.Generic.IEnumerable<K>
{
private readonly global::System.Collections.Generic.IReadOnlyDictionary<K, V> dictionary;

public ReadOnlyDictionaryKeyCollection(global::System.Collections.Generic.IReadOnlyDictionary<K, V> dictionary)
{
if (dictionary == null)
throw new ArgumentNullException(nameof(dictionary));

this.dictionary = dictionary;
}

public global::System.Collections.Generic.IEnumerator<K> GetEnumerator()
{
return new ReadOnlyDictionaryKeyEnumerator(dictionary);
}
IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => GetEnumerator();

private sealed class ReadOnlyDictionaryKeyEnumerator : global::System.Collections.Generic.IEnumerator<K>
{
private readonly global::System.Collections.Generic.IReadOnlyDictionary<K, V> dictionary;
private global::System.Collections.Generic.IEnumerator<global::System.Collections.Generic.KeyValuePair<K, V>> enumeration;

public ReadOnlyDictionaryKeyEnumerator(global::System.Collections.Generic.IReadOnlyDictionary<K, V> dictionary)
{
if (dictionary == null)
throw new ArgumentNullException(nameof(dictionary));

this.dictionary = dictionary;
enumeration = dictionary.GetEnumerator();
}

void IDisposable.Dispose()
{
enumeration.Dispose();
}

public bool MoveNext()
{
return enumeration.MoveNext();
}

object IEnumerator.Current => Current;

public K Current => enumeration.Current.Key;

public void Reset()
{
enumeration = dictionary.GetEnumerator();
}
}
}

private sealed class ReadOnlyDictionaryValueCollection : global::System.Collections.Generic.IEnumerable<V>
{
private readonly global::System.Collections.Generic.IReadOnlyDictionary<K, V> dictionary;

public ReadOnlyDictionaryValueCollection(global::System.Collections.Generic.IReadOnlyDictionary<K, V> dictionary)
{
if (dictionary == null)
throw new ArgumentNullException(nameof(dictionary));

this.dictionary = dictionary;
}

public global::System.Collections.Generic.IEnumerator<V> GetEnumerator()
{
return new ReadOnlyDictionaryValueEnumerator(dictionary);
}
global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() => GetEnumerator();

private sealed class ReadOnlyDictionaryValueEnumerator : global::System.Collections.Generic.IEnumerator<V>
{
private readonly global::System.Collections.Generic.IReadOnlyDictionary<K, V> dictionary;
private global::System.Collections.Generic.IEnumerator<global::System.Collections.Generic.KeyValuePair<K, V>> enumeration;

public ReadOnlyDictionaryValueEnumerator(global::System.Collections.Generic.IReadOnlyDictionary<K, V> dictionary)
{
if (dictionary == null)
throw new ArgumentNullException(nameof(dictionary));

this.dictionary = dictionary;
enumeration = dictionary.GetEnumerator();
}

void IDisposable.Dispose()
{
enumeration.Dispose();
}

public bool MoveNext()
{
return enumeration.MoveNext();
}

object IEnumerator.Current => Current;

public V Current => enumeration.Current.Value;

public void Reset()
{
enumeration = dictionary.GetEnumerator();
}
}
}
}

public class ToAbiHelper : global::Windows.Foundation.Collections.IMapView<K, V>
Expand Down Expand Up @@ -351,30 +352,14 @@ private ConstantSplittableMap(global::System.Collections.Generic.KeyValuePair<K,

public uint Size => (uint)(lastItemIndex - firstItemIndex + 1);

public global::System.Collections.Generic.IEnumerable<K> Keys
public global::System.Collections.Generic.IEnumerable<K> Keys
{
get
{
K[] keys = new K[items.Length];
for (var i = 0; i < items.Length; i++)
{
keys[i] = items[i].Key;
}
return keys;
}
get => new ReadOnlyDictionaryKeyCollection(this);
}

public global::System.Collections.Generic.IEnumerable<V> Values
{
get
{
V[] values = new V[items.Length];
for (var i = 0; i < items.Length; i++)
{
values[i] = items[i].Value;
}
return values;
}
get => new ReadOnlyDictionaryValueCollection(this);
}

public int Count => lastItemIndex - firstItemIndex + 1;
Expand Down
Loading

0 comments on commit 183fc48

Please sign in to comment.