49 lines
1.7 KiB
C#
49 lines
1.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
|
|
namespace Kreta.Framework.Entities
|
|
{
|
|
internal static class EntityAttributeCache
|
|
{
|
|
private static Hashtable m_EntityAttributeCache = new Hashtable();
|
|
|
|
/// <summary>
|
|
/// Visszaadja az entitás nevét a rajta lévő <see cref="EntityAttribute"/> attribútum alapján.
|
|
/// </summary>
|
|
/// <param name="entityType">Az entitás típusa</param>
|
|
/// <returns>Az entitás neve, ha van <see cref="EntityAttribute"/> attribútuma; egyébként 'Ismeretlen'</returns>
|
|
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";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Visszaadja az entitás nevét, cache-elve
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Az entitás nevét a rajta lévő <see cref="EntityAttribute"/> attribútum definiálja.
|
|
/// A névnek rendszer szinten egyedinek kell lennie.
|
|
/// </remarks>
|
|
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;
|
|
}
|
|
}
|
|
}
|