Skip to main content
Version: v13.x - Umbraco 13

IValueMapper Interface

IValueMapper is the interface required when you are creating your own value mapper.

public interface IValueMapper
{
string Name { get; }
string[] Editors { get; }

bool IsMapper(PropertyType propertyType);

TranslationValue GetSourceValue(
string displayName,
string propertyTypeAlias,
object value,
CultureInfoView culture);

object GetTargetValue(
string propertyTypeAlias,
object sourceValue,
TranslationValue values,
CultureInfoView sourceCulture,
CultureInfoView targetCulture);
}

Properties

Name (string)

Name of the value mapper, used to identify the mapper when translations are made.

Editors (string[])

Array containing the property editor aliases that are supported by this mapper.

Methods

IsMapper

bool IsMapper(PropertyType propertyType);

Called to confirm that this value mapper is the correct mapper for the supplied propertyType.

typically this just checks the propertyEditor Alias is in the Editors collection for this mapper.

public  bool IsMapper(PropertyType propertyType)
{
return Editors.InvariantContains(propertyType.PropertyEditorAlias);
}

GetSourceValue

TranslationValue GetSourceValue(
string displayName,
string propertyTypeAlias,
object value,
CultureInfoView culture);

Extracts the source value out of the property and returns a TranslationValue which can contain an nested set of child values.

It is important that if the values are nested that the mapper structures them in such a way that it can reliably locate a value when requested as the order of values within a nested tree cannot be guaranteed.

GetTargetValue

object GetTargetValue(
string propertyTypeAlias,
object sourceValue,
TranslationValue values,
CultureInfoView sourceCulture,
CultureInfoView targetCulture);

Inserts the target values back into the property, this function is the reverse of the GetSourceValue function.

It is worth noting that it receives both the source and target cultures along with the source property editor. This is so the Value mapper can also insert or manage any non translated values that might exist in the source property editor but not the target until translation is completed.