Advertisement
Guest User

Untitled

a guest
Sep 25th, 2020
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. namespace TestConsole
  2. {
  3.     using System;
  4.     using System.Collections;
  5.     using System.Collections.Generic;
  6.  
  7.     public class Collection
  8.     {
  9.         private Dictionary<Type, IList> _dict;
  10.  
  11.         public Collection()
  12.         {
  13.             _dict = new Dictionary<Type, IList>();
  14.         }
  15.  
  16.         public void Add<T>(T item)
  17.             where T : IKek
  18.         {
  19.             var list = GetList<T>();
  20.             list.Add(item);
  21.         }
  22.  
  23.         public List<T> GetList<T>()
  24.             where T : IKek
  25.         {
  26.             if (_dict.TryGetValue(typeof(T), out var list))
  27.             {
  28.                 return list as List<T>;
  29.             }
  30.  
  31.             var newList = new List<T>();
  32.             _dict.Add(typeof(T), newList);
  33.             return newList;
  34.         }
  35.     }
  36.  
  37.     public interface IKek
  38.     {
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement