Resolving Strings to Stuff

Value and action resolvers provide a simple API for taking strings and turning them into values or actions, as well as providing helpful, detailed error messages if a bad string is given or the string causes exceptions while being resolved.

Many of Odin's default attributes contain so-called "resolved strings" - strings that turn into values or actions, often by referencing members via the $ prefix, or by being expressions denoted by the @ prefix. Some of the more popular attributes that use resolved strings are ones like ShowIf, which resolves a string to a boolean value to determine property visibility, and LabelText, which resolves a string to another string (in some cases simply the string itself!), to use as the label of a property.

Before Odin 3.0, this functionality was implemented with a variety of ill-documented and often improvised utilities, and often the code implementing the attribute functionality would simply handle the issue by manually using .NET's reflection API. This was of course sub-optimal in several ways, so with Odin 3.0 we unified all logic for resolved strings into two concepts with a public, solid, extendable and well-documented API: Value Resolvers and Action Resolvers.

With these two new systems, we managed to eliminate every single line of manual reflection code related to resolved strings, throughout all of Odin's drawers, validators and state updaters. This has drastically simplified their implementation.

Value and action resolvers don't just make Odin's own attribute implementations more simple, consistent and feature-rich across the board, though - they also make it effortless for users to create their own attributes that use resolved strings.

So let's take a look at how they work!

Action Resolvers

Action resolvers are the simplest of the two kinds of resolvers; they take a string and "execute" it, without returning or providing a value of any kind.

- Using Action Resolvers

Value Resolvers

Value resolvers take a string and turn it into a value of a specified type, with a bit of magic happening in between.

- Using Value Resolvers

Named Values

Named values are a huge part of the power and convenience of value and action resolvers. Learn about them here!

- Named Values