(I know, I know – we haven’t been explicitly creating FluidValue
objects in prior examples. We’ll explain this when we get to Value Convertors.)
Here are the built-in Fluid values:
StringValue
wraps a string
NumberValue
wraps a decimal
DateTimeValue
wraps a DateTimeOffset
ObjectValue
wraps an object (all Fluid Values extend from this)
BooleanValue
wraps a bool
ArrayValue
wraps a FluidValue[]
DictionaryValue
wraps a dictionary interface
BlankValue
, NilValue
, EmptyValue
don’t wrap anything, but exist for conditional checking
Most of the provided classes have a private field for _value
which holds whatever the original value was.
Fluid Values provide a common interface. Some highlights:
A Type
property which describes what the value is – a String, Number, etc.
A method called WriteTo
which will write out whatever the value should generate. This is where the actual output is generated
A method called GetValue
which will produce a value. Often, this is just the underlying value that’s being wrapped, but as we’ll see later, it can create a value a number of different ways
A method called GetIndex
that is passed when an index is called (ex: people[0]
). It gets a FluidValue
(a NumberValue
in the example), and you can use this to lookup and return any value you like.
A method called Enumerate
using which you can return an IEnumerable<FluidValue>
to be use to iterate values using a for
tag
Methods to convert the Fluid Value into various primitives – numbers, string, etc.
So long as you provide this functionality, you can create your own values. For example, if we wanted to value that wrapped a string and appended “ is awesome” to it when it output, we could do this: