using System;
using System.Collections;
namespace Kreta.Framework.Entities
{
internal static class EntityAttributeCache
{
private static Hashtable m_EntityAttributeCache = new Hashtable();
///
/// Visszaadja az entitás nevét a rajta lévő attribútum alapján.
///
/// Az entitás típusa
/// Az entitás neve, ha van attribútuma; egyébként 'Ismeretlen'
private static string GetEntityName(Type entityType)
{
EntityAttribute[] attributes = (EntityAttribute[])entityType.GetCustomAttributes(typeof(EntityAttribute), true);
if (attributes.Length > 0)
{
return attributes[0].Name;
}
if (entityType.BaseType != null)
{
return GetEntityName(entityType.BaseType);
}
return "Ismeretlen";
}
///
/// Visszaadja az entitás nevét, cache-elve
///
///
/// Az entitás nevét a rajta lévő attribútum definiálja.
/// A névnek rendszer szinten egyedinek kell lennie.
///
internal static string GetEntityNameFromCache(Type entityType)
{
string result = m_EntityAttributeCache[entityType] as string;
if (result == null)
{
result = GetEntityName(entityType);
m_EntityAttributeCache[entityType] = result;
}
return result;
}
}
}