From 762ba241da45ecbd9873e22374291f683eac1b64 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Mon, 17 Jul 2023 15:56:04 +0800 Subject: [PATCH] simple refactoring --- src/Debug/Editor/EcsEditor.cs | 15 +++++++++++++++ src/EntityTemplate/TemplateComponent.cs | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Debug/Editor/EcsEditor.cs b/src/Debug/Editor/EcsEditor.cs index 4fb00c7..51ff38e 100644 --- a/src/Debug/Editor/EcsEditor.cs +++ b/src/Debug/Editor/EcsEditor.cs @@ -1,7 +1,9 @@ #if UNITY_EDITOR using System; +using System.Reflection; using System.Runtime.InteropServices; using UnityEditor; +using UnityEditor.UI; using UnityEngine; namespace DCFApixels.DragonECS.Editors @@ -136,5 +138,18 @@ namespace DCFApixels.DragonECS.Editors } #endregion } + + public static class ReflectionExtensions + { + public static bool TryGetAttribute(this MemberInfo self, out T attrbiute) where T : Attribute + { + attrbiute = self.GetCustomAttribute(); + return attrbiute != null; + } + public static bool HasAttribute(this MemberInfo self) where T : Attribute + { + return self.GetCustomAttribute() != null; + } + } } #endif diff --git a/src/EntityTemplate/TemplateComponent.cs b/src/EntityTemplate/TemplateComponent.cs index 2022ae8..54bb644 100644 --- a/src/EntityTemplate/TemplateComponent.cs +++ b/src/EntityTemplate/TemplateComponent.cs @@ -134,7 +134,7 @@ namespace DCFApixels.DragonECS { if (t.IsSubclassOf(typeof(TemplateComponentInitializer<>))) { - if (t.GetCustomAttribute() != null) + if (t.HasAttribute()) types.Add(t); } }