2022-05-11 13:29:20 -04:00
|
|
|
|
using TriInspector;
|
|
|
|
|
using TriInspector.Processors;
|
|
|
|
|
using TriInspector.Resolvers;
|
|
|
|
|
|
|
|
|
|
[assembly: RegisterTriPropertyDisableProcessor(typeof(DisableIfProcessor))]
|
|
|
|
|
|
|
|
|
|
namespace TriInspector.Processors
|
|
|
|
|
{
|
2022-08-03 04:18:28 -04:00
|
|
|
|
public class DisableIfProcessor : TriPropertyDisableProcessor<DisableIfAttribute>
|
2022-05-11 13:29:20 -04:00
|
|
|
|
{
|
2022-05-14 03:20:25 -04:00
|
|
|
|
private ValueResolver<object> _conditionResolver;
|
2022-05-11 13:29:20 -04:00
|
|
|
|
|
2022-06-06 07:17:53 -04:00
|
|
|
|
public override TriExtensionInitializationResult Initialize(TriPropertyDefinition propertyDefinition)
|
2022-05-11 13:29:20 -04:00
|
|
|
|
{
|
|
|
|
|
base.Initialize(propertyDefinition);
|
|
|
|
|
|
2022-05-14 03:20:25 -04:00
|
|
|
|
_conditionResolver = ValueResolver.Resolve<object>(propertyDefinition, Attribute.Condition);
|
2022-06-03 08:16:23 -04:00
|
|
|
|
if (_conditionResolver.TryGetErrorString(out var error))
|
|
|
|
|
{
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 07:17:53 -04:00
|
|
|
|
return TriExtensionInitializationResult.Ok;
|
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;
|
2022-08-03 04:18:28 -04:00
|
|
|
|
return equal != Attribute.Inverse;
|
2022-05-11 13:29:20 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|