Version 3.3.0.1

ValueResolver class

Namespace: Sirenix.OdinInspector.Editor.ValueResolvers
Assembly: Sirenix.OdinInspector.Editor
public abstract class ValueResolver

A ValueResolver resolves a string to a value of a given type, given an InspectorProperty instance to use as context. Call Get<TResult>(InspectorProperty, String) to get an instance of a ValueResolver.

Value resolvers are a globally extendable system that can be hooked into and modified or changed by creating and registering a ValueResolverCreator.

See Odin's tutorials for details and examples of how to use ValueResolvers.

Inheritance
  • System.Object
  • ValueResolver

Constructors

ValueResolver()
protected ValueResolver()

Fields

Context
The context of this ValueResolver, containing all of its configurations and values it needs to function. For performance and simplicity reasons, this is a single very large struct that is passed around by ref to anything that needs it.
public ValueResolverContext Context

Properties

ErrorMessage
The current error message that the resolver has, or null if there is no error message. This is a shortcut for writing "resolver.Context.ErrorMessage".
public string ErrorMessage { get; }
HasError
Whether there is an error message at the moment. This is a shortcut for writing "resolver.Context.ErrorMessage != null".
public bool HasError { get; }
ValueType
The type of value that this resolver instance is supposed to get.
public abstract Type ValueType { get; }

Methods

DrawError()
Draws an error message box if there is an error, and does nothing if there is no error.
public void DrawError()
DrawErrors(ValueResolver, ValueResolver, ValueResolver, ValueResolver, ValueResolver, ValueResolver, ValueResolver, ValueResolver)
Draws error boxes for all errors in the given value resolvers, or does nothing if there are no errors. This is equivalent to calling DrawError() on all resolvers passed to this method.
public static void DrawErrors(ValueResolver r1 = null, ValueResolver r2 = null, ValueResolver r3 = null, ValueResolver r4 = null, ValueResolver r5 = null, ValueResolver r6 = null, ValueResolver r7 = null, ValueResolver r8 = null)
DrawErrors(ValueResolver, ValueResolver, ValueResolver, ValueResolver, ValueResolver, ValueResolver, ValueResolver, ValueResolver, ValueResolver[])
Draws error boxes for all errors in the given value resolvers, or does nothing if there are no errors. This is equivalent to calling DrawError() on all resolvers passed to this method.
public static void DrawErrors(ValueResolver r1 = null, ValueResolver r2 = null, ValueResolver r3 = null, ValueResolver r4 = null, ValueResolver r5 = null, ValueResolver r6 = null, ValueResolver r7 = null, ValueResolver r8 = null, params ValueResolver[] remainder)
Get(Type, InspectorProperty, String)
Creates a new value resolver instance in a weakly typed fashion, though the result is the same as using a strongly typed generic overload. This is useful when you don't know at compile time which type you want to resolve.
public static ValueResolver Get(Type resultType, InspectorProperty property, string resolvedString)
Parameters
System.Type resultType

The type of value that the new resolver should resolve.

InspectorProperty property

The property that is the context for the resolution to happen in.

System.String resolvedString

The string that should be resolved to a value.

Returns
ValueResolver

Get(Type, InspectorProperty, String, NamedValue[])
Creates a new value resolver instance in a weakly typed fashion, though the result is the same as using a strongly typed generic overload. This is useful when you don't know at compile time which type you want to resolve.
public static ValueResolver Get(Type resultType, InspectorProperty property, string resolvedString, params NamedValue[] namedArgs)
Parameters
System.Type resultType

The type of value that the new resolver should resolve.

InspectorProperty property

The property that is the context for the resolution to happen in.

System.String resolvedString

The string that should be resolved to a value.

NamedValue[] namedArgs

The extra named args that this resolver has access to. Passing in a named arg that already exists will silently override the pre-existing named arg.

Returns
ValueResolver

Get(Type, InspectorProperty, String, Object)
Creates a new value resolver instance in a weakly typed fashion, though the result is the same as using a strongly typed generic overload. This is useful when you don't know at compile time which type you want to resolve.
public static ValueResolver Get(Type resultType, InspectorProperty property, string resolvedString, object fallbackValue)
Parameters
System.Type resultType

The type of value that the new resolver should resolve.

InspectorProperty property

The property that is the context for the resolution to happen in.

System.String resolvedString

The string that should be resolved to a value.

System.Object fallbackValue

The value that the resolver should return if the string cannot be resolved to anything, or if there is an error in creating a resolver, or if resolution itself throws an exception.

Returns
ValueResolver

Get(Type, InspectorProperty, String, Object, NamedValue[])
Creates a new value resolver instance in a weakly typed fashion, though the result is the same as using a strongly typed generic overload. This is useful when you don't know at compile time which type you want to resolve.
public static ValueResolver Get(Type resultType, InspectorProperty property, string resolvedString, object fallbackValue, params NamedValue[] namedArgs)
Parameters
System.Type resultType

The type of value that the new resolver should resolve.

InspectorProperty property

The property that is the context for the resolution to happen in.

System.String resolvedString

The string that should be resolved to a value.

System.Object fallbackValue

The value that the resolver should return if the string cannot be resolved to anything, or if there is an error in creating a resolver, or if resolution itself throws an exception.

NamedValue[] namedArgs

The extra named args that this resolver has access to. Passing in a named arg that already exists will silently override the pre-existing named arg.

Returns
ValueResolver

Get<TResult>(InspectorProperty, String)
Creates a new value resolver instance.
public static ValueResolver<TResult> Get<TResult>(InspectorProperty property, string resolvedString)
Parameters
InspectorProperty property

The property that is the context for the resolution to happen in.

System.String resolvedString

The string that should be resolved to a value.

Returns
ValueResolver<TResult>

Type Parameters
TResult

The type of value that the new resolver should resolve.

Get<TResult>(InspectorProperty, String, TResult)
Creates a new value resolver instance.
public static ValueResolver<TResult> Get<TResult>(InspectorProperty property, string resolvedString, TResult fallbackValue)
Parameters
InspectorProperty property

The property that is the context for the resolution to happen in.

System.String resolvedString

The string that should be resolved to a value.

TResult fallbackValue

The value that the resolver should return if the string cannot be resolved to anything, or if there is an error in creating a resolver, or if resolution itself throws an exception.

Returns
ValueResolver<TResult>

Type Parameters
TResult

The type of value that the new resolver should resolve.

Get<TResult>(InspectorProperty, String, TResult, NamedValue[])
Creates a new value resolver instance.
public static ValueResolver<TResult> Get<TResult>(InspectorProperty property, string resolvedString, TResult fallbackValue, params NamedValue[] namedArgs)
Parameters
InspectorProperty property

The property that is the context for the resolution to happen in.

System.String resolvedString

The string that should be resolved to a value.

TResult fallbackValue

The value that the resolver should return if the string cannot be resolved to anything, or if there is an error in creating a resolver, or if resolution itself throws an exception.

NamedValue[] namedArgs

The extra named args that this resolver has access to. Passing in a named arg that already exists will silently override the pre-existing named arg.

Returns
ValueResolver<TResult>

Type Parameters
TResult

The type of value that the new resolver should resolve.

Get<TResult>(InspectorProperty, String, NamedValue[])
Creates a new value resolver instance.
public static ValueResolver<TResult> Get<TResult>(InspectorProperty property, string resolvedString, params NamedValue[] namedArgs)
Parameters
InspectorProperty property

The property that is the context for the resolution to happen in.

System.String resolvedString

The string that should be resolved to a value.

NamedValue[] namedArgs

The extra named args that this resolver has access to. Passing in a named arg that already exists will silently override the pre-existing named arg.

Returns
ValueResolver<TResult>

Type Parameters
TResult

The type of value that the new resolver should resolve.

GetCombinedErrors(ValueResolver, ValueResolver, ValueResolver, ValueResolver, ValueResolver, ValueResolver, ValueResolver, ValueResolver)
Gets a nicely formatted string that lists all the errors in the given set of value resolvers. The returned value is null if there are no errors.
public static string GetCombinedErrors(ValueResolver r1 = null, ValueResolver r2 = null, ValueResolver r3 = null, ValueResolver r4 = null, ValueResolver r5 = null, ValueResolver r6 = null, ValueResolver r7 = null, ValueResolver r8 = null)
Returns
System.String

GetCombinedErrors(ValueResolver, ValueResolver, ValueResolver, ValueResolver, ValueResolver, ValueResolver, ValueResolver, ValueResolver, ValueResolver[])
Gets a nicely formatted string that lists all the errors in the given set of value resolvers. The returned value is null if there are no errors.
public static string GetCombinedErrors(ValueResolver r1, ValueResolver r2, ValueResolver r3, ValueResolver r4, ValueResolver r5, ValueResolver r6, ValueResolver r7, ValueResolver r8, params ValueResolver[] remainder)
Returns
System.String

GetForString(InspectorProperty, String)

Creates a new value resolver instance meant to resolve a string value in particular. This is a shorthand for creating a string resolver that has the resolved string as a fallback value.

This special case will get you the behaviour where, if you pass in a string that is not meant to be resolved in a special way, the value resolver will just pass you that string back as the result value.

public static ValueResolver<string> GetForString(InspectorProperty property, string resolvedString)
Parameters
InspectorProperty property

The property that is the context for the resolution to happen in.

System.String resolvedString

The string that should be resolved to a value.

Returns
ValueResolver<System.String>

GetForString(InspectorProperty, String, NamedValue[])

Creates a new value resolver instance meant to resolve a string value in particular. This is a shorthand for creating a string resolver that has the resolved string as a fallback value.

This special case will get you the behaviour where, if you pass in a string that is not meant to be resolved in a special way, the value resolver will just pass you that string back as the result value.

public static ValueResolver<string> GetForString(InspectorProperty property, string resolvedString, params NamedValue[] namedArgs)
Parameters
InspectorProperty property

The property that is the context for the resolution to happen in.

System.String resolvedString

The string that should be resolved to a value.

NamedValue[] namedArgs

The extra named args that this resolver has access to. Passing in a named arg that already exists will silently override the pre-existing named arg.

Returns
ValueResolver<System.String>

GetFromContext<TResult>(ref ValueResolverContext)
Creates a new value resolver instance from a pre-built context struct. This is a more advanced use that requires you to know how the context needs to be set up before value resolution happens. However, this allows you to do more advanced things like adjust various context values before string resolution happens.
public static ValueResolver<TResult> GetFromContext<TResult>(ref ValueResolverContext context)
Parameters
ValueResolverContext context

The pre-built context that should be used to get a resolver.

Returns
ValueResolver<TResult>

Type Parameters
TResult

GetFromContextWeak(ref ValueResolverContext)
Creates a new value resolver instance from a pre-built context struct, in a weakly typed fashion, though the result is the same as using a strongly typed generic overload. This is a more advanced use that requires you to know how the context needs to be set up before value resolution happens. However, this allows you to do more advanced things like adjust various context values before string resolution happens.
public static ValueResolver GetFromContextWeak(ref ValueResolverContext context)
Parameters
ValueResolverContext context

The pre-built context that should be used to get a resolver.

Returns
ValueResolver

GetWeakValue(Int32)
Gets a value from the value resolver in a weakly typed manner.
public abstract object GetWeakValue(int selectionIndex = 0)
Parameters
System.Int32 selectionIndex

The selection index at which to get the value, in the case of multi-selection. Defaults to 0.

Returns
System.Object

The value that was gotten.

Derived Classes