using System.Collections.Generic; using XGame.Framework.Map; namespace FL.Map { public static partial class MapKeys { private static Dictionary _nameToKeys; public static MapKey NameToKey(string mapName) { if (_nameToKeys == null) { _nameToKeys = new Dictionary(); } if (_nameToKeys.TryGetValue(mapName, out MapKey key)) { return key; } var property = typeof(MapKeys).GetProperty(mapName, System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.IgnoreCase); if (property != null) { key = property.GetValue(null) as MapKey; _nameToKeys.Add(mapName, key); return key; } XGame.Log.Error($"找不到MapKey. mapName:{mapName}"); return default; } public static void Dispose() { _nameToKeys?.Clear(); _nameToKeys = null; } } }