Exemplo n.º 1
0
 public void Add(DownloadListBoxItem item)
 {
     CheckIfNotContains(item, item.DownloadButton, item.CancelButton, item.RemoveButton);
     downloadToItems.Add(item.DownloadButton, item);
     cancelToItems.Add(item.CancelButton, item);
     removeToItems.Add(item.RemoveButton, item);
 }
Exemplo n.º 2
0
        private void CheckIfNotContains(DownloadListBoxItem item, Button downloadButton, Button cancelButton, Button removeButton)
        {
            if (downloadToItems == null || cancelToItems == null || removeToItems == null)
            {
                throw new NullReferenceException("Dictionary cannot be null");
            }
            if (item == null || downloadButton == null || cancelButton == null || removeButton == null)
            {
                throw new ArgumentNullException("Argument cannot be null");
            }
            if (downloadToItems.ContainsKey(downloadButton) ||
                cancelToItems.ContainsKey(cancelButton) ||
                removeToItems.ContainsKey(removeButton))
            {
                throw new ArgumentException("An element with the same key already exists in the dictionary");
            }

            if (downloadToItems.ContainsValue(item) ||
                cancelToItems.ContainsValue(item) ||
                removeToItems.ContainsValue(item))
            {
                throw new ArgumentException("An element with the same value already exists in the dictionary");
            }
        }