/
NLObP
/
AAEmu
Обзор
Документация
Войти
/
NLObP
/
AAEmu
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
AAEmu.Game/Utils/Scripts/ScriptReflector.cs
56 строк
2 KB
Roger Barreto
Collection expressions check + blank lines update (#1110)
11 дек 2024, 19:38
Не верифицирован
11 дек 2024, 19:38
0ce5643
Код
Авторство
О чём код?
using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using AAEmu.Game.Models.Game; using Microsoft.CodeAnalysis; using NLog; namespace AAEmu.Game.Utils.Scripts; public static class ScriptReflector { private static Logger Logger { get; } = LogManager.GetCurrentClassLogger(); private static Dictionary<string, ScriptObject> _scriptsObjects = []; public static bool Reflect() { OnLoad(); return true; } public static void Clear() { _scriptsObjects.Clear(); } private static void OnLoad() { var hasErrors = false; _scriptsObjects.Clear(); // Load all the scripts that implements ICommand interface var types = Assembly.GetExecutingAssembly().GetTypes().Where(t => t.IsAssignableTo(typeof(ICommand)) && !t.IsInterface && !t.IsAbstract && !t.IsNested && !t.IsAbstract); foreach (var type in types) { try { var obj = Activator.CreateInstance(type); var script = new ScriptObject(type, obj); _scriptsObjects.Add(script.Name, script); script.Invoke("OnLoad"); } catch (Exception e) { hasErrors = true; Logger.Error($"Error in {type}"); Logger.Error(e); } } if (hasErrors) Logger.Warn($"There were some errors when compiling the user scripts !"); // throw new Exception("There were errors in the user scripts !"); } }