2022-05-11 13:29:20 -04:00
|
|
|
|
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>
|
2022-05-14 03:20:25 -04:00
|
|
|
|
where T : ConditionalDisableBaseAttribute
|
2022-05-11 13:29:20 -04:00
|
|
|
|
{
|
|
|
|
|
private readonly bool _inverse;
|
|
|
|
|
|
2022-05-14 03:20:25 -04:00
|
|
|
|
private ValueResolver<object> _conditionResolver;
|
2022-05-11 13:29:20 -04:00
|
|
|
|
|
|
|
|
|
protected DisableIfProcessorBase(bool inverse)
|
|
|
|
|
{
|
|
|
|
|
_inverse = inverse;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Initialize(TriPropertyDefinition propertyDefinition)
|
|
|
|
|
{
|
|
|
|
|
base.Initialize(propertyDefinition);
|
|
|
|
|
|
2022-05-14 03:20:25 -04:00
|
|
|
|
_conditionResolver = ValueResolver.Resolve<object>(propertyDefinition, Attribute.Condition);
|
2022-05-11 13:29:20 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public sealed override bool IsDisabled(TriProperty property)
|
|
|
|
|
{
|
2022-05-14 03:20:25 -04:00
|
|
|
|
var val = _conditionResolver.GetValue(property);
|
|
|
|
|
var equal = val?.Equals(Attribute.Value) ?? Attribute.Value == null;
|
|
|
|
|
return equal != _inverse;
|
2022-05-11 13:29:20 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public sealed class DisableIfProcessor : DisableIfProcessorBase<DisableIfAttribute>
|
|
|
|
|
{
|
|
|
|
|
public DisableIfProcessor() : base(false)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public sealed class EnableIfProcessor : DisableIfProcessorBase<EnableIfAttribute>
|
|
|
|
|
{
|
|
|
|
|
public EnableIfProcessor() : base(true)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|