Files
OpenRA/OpenRa.DataStructures/TypeDictionary.cs
Bob 80bcd23ba7 Traits is now data-driven. Actor.cs is now SMALL. (win)
- FieldLoader can now handle arrays. This might be useful for Prerequisites, Owner fields.
2009-10-20 18:17:08 +13:00

44 lines
723 B
C#
Executable File

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