2022-05-11 13:29:20 -04:00
|
|
|
|
using TriInspector;
|
|
|
|
|
using TriInspector.Processors;
|
|
|
|
|
using TriInspector.Resolvers;
|
|
|
|
|
|
|
|
|
|
[assembly: RegisterTriPropertyHideProcessor(typeof(HideIfProcessor))]
|
|
|
|
|
[assembly: RegisterTriPropertyHideProcessor(typeof(ShowIfProcessor))]
|
|
|
|
|
|
|
|
|
|
namespace TriInspector.Processors
|
|
|
|
|
{
|
|
|
|
|
public abstract class HideIfProcessorBase<T> : TriPropertyHideProcessor<T>
|
2022-05-14 03:20:25 -04:00
|
|
|
|
where T : ConditionalHideBaseAttribute
|
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 HideIfProcessorBase(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 IsHidden(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 HideIfProcessor : HideIfProcessorBase<HideIfAttribute>
|
|
|
|
|
{
|
|
|
|
|
public HideIfProcessor() : base(false)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public sealed class ShowIfProcessor : HideIfProcessorBase<ShowIfAttribute>
|
|
|
|
|
{
|
|
|
|
|
public ShowIfProcessor() : base(true)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|