using JetBrains.Annotations; namespace TriInspector.Resolvers { public static class ValueResolver { public static ValueResolver Resolve(TriPropertyDefinition propertyDefinition, string expression) { if (InstanceFieldValueResolver.TryResolve(propertyDefinition, expression, out var ifr)) { return ifr; } if (InstancePropertyValueResolver.TryResolve(propertyDefinition, expression, out var ipr)) { return ipr; } if (InstanceMethodValueResolver.TryResolve(propertyDefinition, expression, out var imr)) { return imr; } return new ErrorValueResolver(propertyDefinition, expression); } public static ValueResolver ResolveString(TriPropertyDefinition propertyDefinition, string expression) { if (expression != null && expression.StartsWith("$")) { return Resolve(propertyDefinition, expression.Substring(1)); } return new ConstantValueResolver(expression); } } public abstract class ValueResolver { [PublicAPI] public abstract bool TryGetErrorString(out string error); [PublicAPI] public abstract T GetValue(TriProperty property, T defaultValue = default); } public sealed class ConstantValueResolver : ValueResolver { private readonly T _value; public ConstantValueResolver(T value) { _value = value; } public override bool TryGetErrorString(out string error) { error = default; return false; } public override T GetValue(TriProperty property, T defaultValue = default) { return _value; } } }