public void TestDictionary() { // Default ctor. var data = Enumerable.Range(1, 5).ToDictionary(x => x, x => x.ToString()); var dict = new ReadOnlyDictionary <int, string>(data); Assert.AreEqual(5, dict.Count); Assert.IsTrue(dict.IsReadOnly); CollectionAssert.AreEqual(data, dict); CollectionAssert.AreEqual(data.Keys, dict.Keys); CollectionAssert.AreEqual(data.Values, dict.Values); Assert.IsTrue(dict.GetEnumerator().MoveNext()); Assert.IsTrue(((IEnumerable)dict).GetEnumerator().MoveNext()); Assert.IsTrue(dict.ContainsKey(1)); Assert.IsTrue(dict.Contains(new KeyValuePair <int, string>(4, "4"))); Assert.AreEqual("3", dict[3]); string val; Assert.IsTrue(dict.TryGetValue(2, out val)); Assert.AreEqual("2", val); var arr = new KeyValuePair <int, string> [5]; dict.CopyTo(arr, 0); CollectionAssert.AreEqual(data, arr); Assert.Throws <NotSupportedException>(() => dict.Add(1, "2")); Assert.Throws <NotSupportedException>(() => dict.Add(new KeyValuePair <int, string>(1, "2"))); Assert.Throws <NotSupportedException>(() => dict.Clear()); Assert.Throws <NotSupportedException>(() => dict.Remove(1)); Assert.Throws <NotSupportedException>(() => dict.Remove(new KeyValuePair <int, string>(1, "2"))); }
private static bool AnyDesire( ReadOnlyDictionary <EventType, Desire.Type> table, Desire.Type type) { using (IEnumerator <KeyValuePair <EventType, Desire.Type> > enumerator = table.GetEnumerator()) { while (enumerator.MoveNext()) { if (enumerator.Current.Value == type) { return(true); } } } return(false); }
private static KeyValuePair <EventType, Desire.Type> FirstDesire( ReadOnlyDictionary <EventType, Desire.Type> table, Desire.Type type) { using (IEnumerator <KeyValuePair <EventType, Desire.Type> > enumerator = table.GetEnumerator()) { while (enumerator.MoveNext()) { KeyValuePair <EventType, Desire.Type> current = enumerator.Current; if (current.Value == type) { return(current); } } } return(new KeyValuePair <EventType, Desire.Type>()); }
public static void SerializeStatic(ref JsonWriter writer, ReadOnlyDictionary <string, TValue> value, JsonSerializerOptions options) #endif { if (value is null) { writer.WriteNull(); return; } if (writer.Depth >= options.MaxDepth) { writer.Writer.WriteEmptyObject(); return; } ++writer.Depth; writer.WriteBeginObject(); var e = value.GetEnumerator(); try { if (!e.MoveNext()) { goto END; } var tuple = e.Current; var propertyName = tuple.Key; Debug.Assert(propertyName != null, nameof(propertyName) + " != null"); writer.WritePropertyName(propertyName); #if !ENABLE_IL2CPP var valueSerializer = options.Resolver.GetSerializeStatic <TValue>(); if (valueSerializer.ToPointer() != null) { writer.Serialize(tuple.Value, options, valueSerializer); while (e.MoveNext()) { writer.WriteValueSeparator(); tuple = e.Current; propertyName = tuple.Key; Debug.Assert(propertyName != null, nameof(propertyName) + " != null"); writer.WritePropertyName(propertyName); writer.Serialize(tuple.Value, options, valueSerializer); } goto END; } #endif var valueFormatter = options.Resolver.GetFormatterWithVerify <TValue>(); valueFormatter.Serialize(ref writer, tuple.Value, options); while (e.MoveNext()) { writer.WriteValueSeparator(); tuple = e.Current; propertyName = tuple.Key; Debug.Assert(propertyName != null, nameof(propertyName) + " != null"); writer.WritePropertyName(propertyName); valueFormatter.Serialize(ref writer, tuple.Value, options); } } finally { e.Dispose(); } END: writer.WriteEndObject(); --writer.Depth; }
public IEnumerator <KeyValuePair <string, IMemberAccessor> > GetEnumerator() { return(members.GetEnumerator()); }
IEnumerator IEnumerable.GetEnumerator() { return(_tiles.GetEnumerator()); }
/// <inheritdoc cref="cAPIDocumentationTemplate.GetEnumerator"/> public IEnumerator <KeyValuePair <string, string> > GetEnumerator() => mDictionary.GetEnumerator();
public IEnumerator <KeyValuePair <TKey, TValue> > GetEnumerator() => _map.GetEnumerator();
public void GetEnumeratorTest() { Assert.AreEqual(baseObject.GetEnumerator(), testObject.GetEnumerator()); Assert.AreEqual(baseObject.GetEnumerator(), ((IEnumerable)testObject).GetEnumerator()); }
public void ReadOnlyDictionary_Unit_GetEnumerator2_Optimal() { IDictionary<String, String> dictionary = new Dictionary<String, String>() { { "Key1", "Value1" }, { "Key2", "Value2" }, { "Key3", "Value3" } }; IEnumerable target = new ReadOnlyDictionary<String, String>(dictionary); IEnumerator actual = target.GetEnumerator(); Int32 count = 0; while (actual.MoveNext()) { count++; Assert.IsTrue(dictionary.Contains((KeyValuePair<String, String>)actual.Current)); } Assert.AreEqual(dictionary.Count, count); }
public IEnumerator <KeyValuePair <K, V> > GetEnumerator() { return(wrapped.GetEnumerator()); }