diff --git a/src/Debug/EcsDebugUtility.cs b/src/Debug/EcsDebugUtility.cs index ad71481..5ba06ec 100644 --- a/src/Debug/EcsDebugUtility.cs +++ b/src/Debug/EcsDebugUtility.cs @@ -1,12 +1,16 @@ using System; using System.Collections.Generic; +#if (DEBUG && !DISABLE_DEBUG) || !REFLECTION_DISABLED using System.Reflection; +#endif namespace DCFApixels.DragonECS { public static class EcsDebugUtility { +#if (DEBUG && !DISABLE_DEBUG) || !REFLECTION_DISABLED private const BindingFlags RFL_FLAGS = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; +#endif #region GetGenericTypeName public static string GetGenericTypeFullName(int maxDepth = 2) @@ -15,7 +19,7 @@ namespace DCFApixels.DragonECS } public static string GetGenericTypeFullName(Type type, int maxDepth = 2) { - return GetGenericTypeNameInternal(type, maxDepth, true); + return GetGenericTypeName_Internal(type, maxDepth, true); } public static string GetGenericTypeName(int maxDepth = 2) { @@ -23,10 +27,11 @@ namespace DCFApixels.DragonECS } public static string GetGenericTypeName(Type type, int maxDepth = 2) { - return GetGenericTypeNameInternal(type, maxDepth, false); + return GetGenericTypeName_Internal(type, maxDepth, false); } - private static string GetGenericTypeNameInternal(Type type, int maxDepth, bool isFull) + private static string GetGenericTypeName_Internal(Type type, int maxDepth, bool isFull) { +#if (DEBUG && !DISABLE_DEBUG) || !REFLECTION_DISABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает string typeName = isFull ? type.FullName : type.Name; if (!type.IsGenericType || maxDepth == 0) { @@ -47,6 +52,10 @@ namespace DCFApixels.DragonECS genericParams += (i == 0 ? paramTypeName : $", {paramTypeName}"); } return $"{typeName}<{genericParams}>"; +#else + EcsDebug.PrintWarning($"Reflection is not available, the {nameof(GetGenericTypeName_Internal)} method does not work."); + return isFull ? type.FullName : type.Name; +#endif } #endregion @@ -56,10 +65,11 @@ namespace DCFApixels.DragonECS { return AutoToString(self, typeof(T), isWriteName); } + + //TODO сделать специальный вывод в виде названий констант для Enum-ов private static string AutoToString(object target, Type type, bool isWriteName) { -#if !REFLECTION_DISABLED - //TODO сделать специальный вывод в виде названий констант для Enum-ов +#if (DEBUG && !DISABLE_DEBUG) || !REFLECTION_DISABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает #pragma warning disable IL2070 // 'this' argument does not satisfy 'DynamicallyAccessedMembersAttribute' in call to target method. The parameter of method does not have matching annotations. var fields = type.GetFields(RFL_FLAGS); #pragma warning restore IL2070 @@ -283,7 +293,7 @@ namespace DCFApixels.DragonECS } #endregion - #region TypeMetaSource + #region TypeMetaProvider public static bool IsTypeMetaProvided(object obj) { return obj is IEcsTypeMetaProvider; diff --git a/src/Debug/TypeMeta.cs b/src/Debug/TypeMeta.cs index 2b538bc..a8c252f 100644 --- a/src/Debug/TypeMeta.cs +++ b/src/Debug/TypeMeta.cs @@ -3,7 +3,9 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; +#if (DEBUG && !DISABLE_DEBUG) || !REFLECTION_DISABLED using System.Reflection; +#endif namespace DCFApixels.DragonECS { @@ -81,14 +83,7 @@ namespace DCFApixels.DragonECS if (_initFlags.HasFlag(InitFlag.Name) == false) { (_name, _isCustomName) = MetaGenerator.GetMetaName(_type); - if (_isCustomName) - { - _typeName = MetaGenerator.GetTypeName(_type); - } - else - { - _typeName = _name; - } + _typeName = _isCustomName ? MetaGenerator.GetTypeName(_type) : _name; _initFlags |= InitFlag.Name; } } @@ -301,12 +296,12 @@ namespace DCFApixels.DragonECS //private static HashSet _; - #region GetMemberType - public static EcsMemberType GetMemberType(Type type) - { - throw new NotImplementedException(); - } - #endregion + //#region GetMemberType + //public static EcsMemberType GetMemberType(Type type) + //{ + // throw new NotImplementedException(); + //} + //#endregion #region GetMetaName/GetTypeName public static string GetTypeName(Type type) @@ -315,6 +310,7 @@ namespace DCFApixels.DragonECS } public static (string, bool) GetMetaName(Type type) { +#if (DEBUG && !DISABLE_DEBUG) || !REFLECTION_DISABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает bool isCustom = type.TryGetCustomAttribute(out MetaNameAttribute atr) && string.IsNullOrEmpty(atr.name) == false; if (isCustom) { @@ -332,6 +328,10 @@ namespace DCFApixels.DragonECS return ($"{atr.name}<{genericParams}>", isCustom); } return (EcsDebugUtility.GetGenericTypeName(type, GENERIC_NAME_DEPTH), isCustom); +#else + EcsDebug.PrintWarning($"Reflection is not available, the {nameof(MetaGenerator)}.{nameof(GetMetaName)} method does not work."); + return (type.Name, false); +#endif } #endregion @@ -342,35 +342,55 @@ namespace DCFApixels.DragonECS } public static (MetaColor, bool) GetColor(Type type) { +#if (DEBUG && !DISABLE_DEBUG) || !REFLECTION_DISABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает bool isCustom = type.TryGetCustomAttribute(out MetaColorAttribute atr); return (isCustom ? atr.color : AutoColor(type), isCustom); +#else + EcsDebug.PrintWarning($"Reflection is not available, the {nameof(MetaGenerator)}.{nameof(GetColor)} method does not work."); + return (AutoColor(type), false); +#endif } #endregion #region GetGroup public static MetaGroup GetGroup(Type type) { +#if (DEBUG && !DISABLE_DEBUG) || !REFLECTION_DISABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает return type.TryGetCustomAttribute(out MetaGroupAttribute atr) ? atr.Data : MetaGroup.Empty; +#else + EcsDebug.PrintWarning($"Reflection is not available, the {nameof(MetaGenerator)}.{nameof(GetGroup)} method does not work."); + return MetaGroup.Empty; +#endif } #endregion #region GetDescription public static MetaDescription GetDescription(Type type) { +#if (DEBUG && !DISABLE_DEBUG) || !REFLECTION_DISABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает bool isCustom = type.TryGetCustomAttribute(out MetaDescriptionAttribute atr); return isCustom ? atr.Data : MetaDescription.Empty; +#else + EcsDebug.PrintWarning($"Reflection is not available, the {nameof(MetaGenerator)}.{nameof(GetDescription)} method does not work."); + return MetaDescription.Empty; +#endif } #endregion #region GetTags public static IReadOnlyList GetTags(Type type) { +#if (DEBUG && !DISABLE_DEBUG) || !REFLECTION_DISABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает var atr = type.GetCustomAttribute(); return atr != null ? atr.Tags : Array.Empty(); +#else + EcsDebug.PrintWarning($"Reflection is not available, the {nameof(MetaGenerator)}.{nameof(GetTags)} method does not work."); + return Array.Empty(); +#endif } #endregion } - #endregion +#endregion } public enum EcsMemberType : byte