//************************************************************************ // https://github.com/yuzhengyang // author: yuzhengyang // date: 2017.7.31 - 2017.7.31 // desc: Form唯一字典工具 // Copyright (c) yuzhengyang. All rights reserved. //************************************************************************ using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; namespace Y.Utils.DataUtils.Collections { /// /// Form唯一字典工具 /// public class FormDictionaryTool { protected ConcurrentDictionary dictionary = new ConcurrentDictionary(); public T Get() where T : Form { if (dictionary.ContainsKey(typeof(T))) { Form value; if (dictionary.TryGetValue(typeof(T), out value)) { if (value != null && !value.IsDisposed) { return (T)value; } } } T form = default(T); if (dictionary.TryAdd(typeof(T), form)) { return form; } return null; } } }