Value Mappers
Value Mappers control the mapping of content property values in and out of Umbraco.
Mapping​
For most properties we don't need to map values but occasionally a value might contain an internal ID or something else that needs to be turned into something more generic.
Dependency​
A far more common requirement is to get a list of dependencies for a property. Dependencies are used by uSync.Exporter and uSync.Publisher when calculating what additional items to include for syncing content.
ISyncMapper​
All value mappers need to implement the ISyncMapper interface.
public interface ISyncMapper
{
string Name { get; }
string[] Editors { get; }
bool IsMapper(PropertyType propertyType);
string GetExportValue(object value, string editorAlias);
string GetImportValue(string value, string editorAlias);
IEnumerable<uSyncDependency> GetDependencies(
object value, string editorAlias, DependencyFlags flags);
}
Value | Note |
---|---|
Name | Name for the Mapper, will appear in logs to aid debugging. |
Editors | Collection of EditorAliases for the DataTypes that the mapper handles. |
IsMapper | Confirms that this mapper will map the propertyType supplied. |
SyncValueMapperBase​
To aid with ValueMapper implementation, you should use the SyncValueMapperBase class from the uSync.ContentMapper assembly. This base class handles some of the repetitive elements and has helpers for dependency checks.
Examples​
See the uSync Mappers Source for examples of how mappers can be implemented.