mirror of
https://github.com/codewriter-packages/Tri-Inspector.git
synced 2025-01-22 16:28:23 -05:00
50 lines
1.5 KiB
C#
50 lines
1.5 KiB
C#
using TriInspector;
|
|
using TriInspector.Processors;
|
|
using TriInspector.Resolvers;
|
|
|
|
[assembly: RegisterTriPropertyDisableProcessor(typeof(DisableIfProcessor))]
|
|
[assembly: RegisterTriPropertyDisableProcessor(typeof(EnableIfProcessor))]
|
|
|
|
namespace TriInspector.Processors
|
|
{
|
|
public abstract class DisableIfProcessorBase<T> : TriPropertyDisableProcessor<T>
|
|
where T : ConditionalDisableBaseAttribute
|
|
{
|
|
private readonly bool _inverse;
|
|
|
|
private ValueResolver<object> _conditionResolver;
|
|
|
|
protected DisableIfProcessorBase(bool inverse)
|
|
{
|
|
_inverse = inverse;
|
|
}
|
|
|
|
public override void Initialize(TriPropertyDefinition propertyDefinition)
|
|
{
|
|
base.Initialize(propertyDefinition);
|
|
|
|
_conditionResolver = ValueResolver.Resolve<object>(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<DisableIfAttribute>
|
|
{
|
|
public DisableIfProcessor() : base(false)
|
|
{
|
|
}
|
|
}
|
|
|
|
public sealed class EnableIfProcessor : DisableIfProcessorBase<EnableIfAttribute>
|
|
{
|
|
public EnableIfProcessor() : base(true)
|
|
{
|
|
}
|
|
}
|
|
} |