diff --git a/src/Debug/EcsDebugUtility.cs b/src/Debug/EcsDebugUtility.cs index e16726c..239b269 100644 --- a/src/Debug/EcsDebugUtility.cs +++ b/src/Debug/EcsDebugUtility.cs @@ -193,32 +193,32 @@ namespace DCFApixels.DragonECS #endregion #region GetGroup - public static MetaGroup GetGroup(object obj) + public static ReadonlyMetaGroup GetGroup(object obj) { return GetTypeMeta(obj).Group; } - public static MetaGroup GetGroup() + public static ReadonlyMetaGroup GetGroup() { return GetTypeMeta().Group; } - public static MetaGroup GetGroup(Type type) + public static ReadonlyMetaGroup GetGroup(Type type) { return GetTypeMeta(type).Group; } - public static bool TryGetGroup(object obj, out MetaGroup group) + public static bool TryGetGroup(object obj, out ReadonlyMetaGroup group) { TypeMeta meta = GetTypeMeta(obj); group = meta.Group; return group.IsNull; } - public static bool TryGetGroup(out MetaGroup group) + public static bool TryGetGroup(out ReadonlyMetaGroup group) { TypeMeta meta = GetTypeMeta(); group = meta.Group; return group.IsNull; } - public static bool TryGetGroup(Type type, out MetaGroup group) + public static bool TryGetGroup(Type type, out ReadonlyMetaGroup group) { TypeMeta meta = GetTypeMeta(type); group = meta.Group; @@ -308,7 +308,15 @@ namespace DCFApixels.DragonECS } - public sealed class TypeMeta + public interface ITypeMeta + { + public string Name { get; } + public MetaColor Color { get; } + public string Description { get; } + public ReadonlyMetaGroup Group { get; } + public IReadOnlyCollection Tags { get; } + } + public sealed class TypeMeta : ITypeMeta { internal readonly Type _type; @@ -319,7 +327,7 @@ namespace DCFApixels.DragonECS private string _name; private MetaColor _color; private string _description; - private MetaGroup _group; + private ReadonlyMetaGroup _group; private IReadOnlyCollection _tags; private int _typeCode; @@ -409,7 +417,7 @@ namespace DCFApixels.DragonECS #endregion #region Group - public MetaGroup Group + public ReadonlyMetaGroup Group { get { @@ -539,9 +547,9 @@ namespace DCFApixels.DragonECS.Internal #endregion #region GetGroup - public static MetaGroup GetGroup(Type type) + public static ReadonlyMetaGroup GetGroup(Type type) { - return type.TryGetCustomAttribute(out MetaGroupAttribute atr) ? atr.GetData() : MetaGroup.Empty; + return type.TryGetCustomAttribute(out MetaGroupAttribute atr) ? atr.Data : ReadonlyMetaGroup.Empty; } #endregion diff --git a/src/Debug/MetaAttributes/MetaGroupAttribute.cs b/src/Debug/MetaAttributes/MetaGroupAttribute.cs index 8b39ee9..694781b 100644 --- a/src/Debug/MetaAttributes/MetaGroupAttribute.cs +++ b/src/Debug/MetaAttributes/MetaGroupAttribute.cs @@ -1,14 +1,22 @@ using System; using System.Collections.Generic; -using System.Text.RegularExpressions; namespace DCFApixels.DragonECS { [AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class | AttributeTargets.Interface, Inherited = false, AllowMultiple = false)] public sealed class MetaGroupAttribute : EcsMetaAttribute { - public static readonly MetaGroupAttribute Empty = new MetaGroupAttribute(""); - public readonly string name; + public readonly MetaGroup Data; + public MetaGroupAttribute(string name) + { + Data = new MetaGroup(name); + } + } + public class MetaGroup + { + public static readonly MetaGroup Empty = new MetaGroup(""); + + public readonly string Name; private string[] path = null; public IReadOnlyCollection Splited { @@ -16,28 +24,34 @@ namespace DCFApixels.DragonECS { if (path == null) { - path = Regex.Split(name, @"[/|\\]"); + path = Name.Split('/', StringSplitOptions.RemoveEmptyEntries); } return path; } } - public MetaGroupAttribute(string name) + public MetaGroup(string name) { - name = Regex.Replace(name, @"^[/|\\]+|[/|\\]+$", ""); - this.name = name; - } - public MetaGroup GetData() - { - return new MetaGroup(this); + if (string.IsNullOrEmpty(name)) + { + Name = string.Empty; + return; + } + name = name.Replace('\\', '/'); + if (name[name.Length - 1] != '/') + { + name += '/'; + } + Name = name; } } - public readonly struct MetaGroup + + public readonly struct ReadonlyMetaGroup { - public static readonly MetaGroup Empty = new MetaGroup(MetaGroupAttribute.Empty); - private readonly MetaGroupAttribute _source; + public static readonly ReadonlyMetaGroup Empty = new ReadonlyMetaGroup(MetaGroup.Empty); + private readonly MetaGroup _source; public string Name { - get { return _source.name; } + get { return _source.Name; } } public IReadOnlyCollection Splited { @@ -47,9 +61,14 @@ namespace DCFApixels.DragonECS { get { return _source == null; } } - public MetaGroup(MetaGroupAttribute source) + public ReadonlyMetaGroup(MetaGroup source) { _source = source; } + + public static implicit operator ReadonlyMetaGroup(MetaGroup group) + { + return new ReadonlyMetaGroup(group); + } } }