using TriInspector; using TriInspector.Processors; using TriInspector.Resolvers; [assembly: RegisterTriPropertyDisableProcessor(typeof(DisableIfProcessor))] [assembly: RegisterTriPropertyDisableProcessor(typeof(EnableIfProcessor))] namespace TriInspector.Processors { public abstract class DisableIfProcessorBase : TriPropertyDisableProcessor where T : ConditionalDisableBaseAttribute { private readonly bool _inverse; private ValueResolver _conditionResolver; protected DisableIfProcessorBase(bool inverse) { _inverse = inverse; } public override void Initialize(TriPropertyDefinition propertyDefinition) { base.Initialize(propertyDefinition); _conditionResolver = ValueResolver.Resolve(propertyDefinition, Attribute.Condition); } public sealed override bool IsDisabled(TriProperty property) { var val = _conditionResolver.GetValue(property); var equal = val?.Equals(Attribute.Value) ?? Attribute.Value == null; return equal != _inverse; } } public sealed class DisableIfProcessor : DisableIfProcessorBase { public DisableIfProcessor() : base(false) { } } public sealed class EnableIfProcessor : DisableIfProcessorBase { public EnableIfProcessor() : base(true) { } } }