ModernUO/Scripts/Engines/MLQuests/QuesterNameAttribute.cs
2018-09-14 08:41:38 -07:00

39 lines
960 B
C#

using System;
using System.Collections.Generic;
namespace Server.Engines.MLQuests
{
[AttributeUsage( AttributeTargets.Class )]
public class QuesterNameAttribute : Attribute
{
private string m_QuesterName;
public string QuesterName => m_QuesterName;
public QuesterNameAttribute( string questerName )
{
m_QuesterName = questerName;
}
private static readonly Type m_Type = typeof( QuesterNameAttribute );
private static readonly Dictionary<Type, string> m_Cache = new Dictionary<Type, string>();
public static string GetQuesterNameFor( Type t )
{
if ( t == null )
return "";
if (m_Cache.TryGetValue( t, out string result ))
return result;
object[] attributes = t.GetCustomAttributes( m_Type, false );
if ( attributes.Length != 0 )
result = ( (QuesterNameAttribute)attributes[0] ).QuesterName;
else
result = t.Name;
return ( m_Cache[t] = result );
}
}
}