Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace TestConsole
- {
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- public class Collection
- {
- private Dictionary<string, IList> _dict;
- public Collection()
- {
- _dict = new Dictionary<string, IList>();
- }
- public void Add<T>(string key, T item)
- where T : IKek
- {
- var list = GetList<T>(key);
- list.Add(item);
- }
- public List<T> GetList<T>(string key)
- where T : IKek
- {
- if (_dict.TryGetValue(key, out var list) && (list is List<T> concrecList))
- {
- return concrecList;
- }
- var newList = new List<T>();
- _dict.Add(key, newList);
- return newList;
- }
- public IEnumerator<T> GetEnumerator<T>(string key)
- where T : IKek
- {
- return GetList<T>(key).GetEnumerator();
- }
- }
- public interface IKek
- {
- public string Text { get; set; }
- public string Code { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement