using System; using System.Collections.Generic; using System.Text; namespace OpenRa { public class TypeDictionary { Dictionary inner = new Dictionary(); public void Add( Type t, object val ) { inner.Add( t, val ); } public void Add( T val ) { Add( typeof( T ), val ); } public void Remove() { inner.Remove( typeof( T ) ); } public bool Contains() { return inner.ContainsKey( typeof( T ) ); } public T Get() { return (T)inner[ typeof( T ) ]; } public T GetOrDefault() { object o = null; inner.TryGetValue(typeof(T), out o); return (T)o; } public IEnumerable WithInterface() { foreach( var i in inner ) if( i.Value is T ) yield return (T)i.Value; } } }