diff --git a/src/DebugUtils/MetaAttributes/MetaIDAttribute.cs b/src/DebugUtils/MetaAttributes/MetaIDAttribute.cs index cc798de..67b876f 100644 --- a/src/DebugUtils/MetaAttributes/MetaIDAttribute.cs +++ b/src/DebugUtils/MetaAttributes/MetaIDAttribute.cs @@ -1,6 +1,7 @@ using DCFApixels.DragonECS.Internal; using System; using System.Runtime.InteropServices; +using System.Text.RegularExpressions; namespace DCFApixels.DragonECS { @@ -14,16 +15,16 @@ namespace DCFApixels.DragonECS { Throw.ArgumentNull(nameof(id)); } - if (id.Contains(',')) + if (MetaID.IsGenericID(id) == false) { - Throw.ArgumentException($"Аргумент {nameof(id)} не может содержать символ запятой ','"); + Throw.ArgumentException($"Иентификатор {id} содержит не допустимые символы: ,<>"); } id = string.Intern(id); ID = id; } } - public static class MetaIDUtility + public static class MetaID { [ThreadStatic] private static Random _randon; @@ -32,6 +33,11 @@ namespace DCFApixels.DragonECS [ThreadStatic] private static bool _isInit; + public static bool IsGenericID(string id) + { + return Regex.IsMatch(id, @"^[^,<>\s]*$"); + } + public static unsafe string GenerateNewUniqueID() { if (_isInit == false) @@ -56,9 +62,13 @@ namespace DCFApixels.DragonECS return BitConverter.ToString(_buffer).Replace("-", ""); } - public static unsafe string GenerateNewUniqueIDWithAttribute() + public static string IDToAttribute(string id) { - return $"[MetaID(\"{GenerateNewUniqueID()}\")]"; + return $"[MetaID(\"id\")]"; + } + public static string GenerateNewUniqueIDWithAttribute() + { + return IDToAttribute(GenerateNewUniqueID()); } } -} +} \ No newline at end of file diff --git a/src/DebugUtils/TypeMeta.cs b/src/DebugUtils/TypeMeta.cs index 55bcf70..0fee594 100644 --- a/src/DebugUtils/TypeMeta.cs +++ b/src/DebugUtils/TypeMeta.cs @@ -498,11 +498,16 @@ namespace DCFApixels.DragonECS } else { - if (_idTypePairs.TryGetValue(atr.ID, out Type otherType) && type != otherType) //этот ексепшен не работает, так как атрибуты не кешируются а пересоздаются + string id = atr.ID; + if (type.IsGenericType && type.IsGenericTypeDefinition == false) { - Throw.Exception($"Types {type.Name} and {otherType.Name} have duplicate MetaID identifiers."); + id = $"{id}<{string.Join(", ", type.GetGenericArguments().Select(o => GetMetaID(o)))}>"; } - _idTypePairs.Add(atr.ID, type); + if (_idTypePairs.TryGetValue(id, out Type otherType) && type != otherType) //этот ексепшен не работает, так как атрибуты не кешируются а пересоздаются + { + Throw.Exception($"Types {type.ToMeta().TypeName} and {otherType.ToMeta().TypeName} have duplicate {atr.ID} MetaID."); + } + _idTypePairs[atr.ID] = type; return atr.ID; } #else