simple refactoring

This commit is contained in:
Mikhail 2023-07-17 15:56:04 +08:00
parent f8c95fbd98
commit 762ba241da
2 changed files with 16 additions and 1 deletions

View File

@ -1,7 +1,9 @@
#if UNITY_EDITOR #if UNITY_EDITOR
using System; using System;
using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using UnityEditor; using UnityEditor;
using UnityEditor.UI;
using UnityEngine; using UnityEngine;
namespace DCFApixels.DragonECS.Editors namespace DCFApixels.DragonECS.Editors
@ -136,5 +138,18 @@ namespace DCFApixels.DragonECS.Editors
} }
#endregion #endregion
} }
public static class ReflectionExtensions
{
public static bool TryGetAttribute<T>(this MemberInfo self, out T attrbiute) where T : Attribute
{
attrbiute = self.GetCustomAttribute<T>();
return attrbiute != null;
}
public static bool HasAttribute<T>(this MemberInfo self) where T : Attribute
{
return self.GetCustomAttribute<T>() != null;
}
}
} }
#endif #endif

View File

@ -134,7 +134,7 @@ namespace DCFApixels.DragonECS
{ {
if (t.IsSubclassOf(typeof(TemplateComponentInitializer<>))) if (t.IsSubclassOf(typeof(TemplateComponentInitializer<>)))
{ {
if (t.GetCustomAttribute<SerializableAttribute>() != null) if (t.HasAttribute<SerializableAttribute>())
types.Add(t); types.Add(t);
} }
} }