Enterspeed Value Converter
A property value converter is a class that will convert the input value from Umbraco into an IEnterspeedProperty. To implement your own converter you need to implement the IEnterspeedPropertyValueConverter interface
IEnterspeedPropertyValueConverter
This interface contains two methods that need to be implemented
IsConverter
bool IsConverter(IPublishedPropertyType propertyType);
This method is called when the EnterspeedPropertyService tries to find the proper converter for this property.
An implementation of this method could look like this:
public bool IsConverter(IPublishedPropertyType propertyType)
{
return propertyType.EditorAlias.Equals("Umbraco.TextBox");
}
Convert
IEnterspeedProperty Convert(IPublishedProperty property, string culture);
This is the method that is converting the Umbraco property to an IEnterspeedProperty.
An implementation of this method could look like this:
public IEnterspeedProperty Convert(IPublishedProperty property, string culture)
{
var value = property.GetValue<string>(culture);
return new StringEnterspeedProperty(property.Alias, value);
}
Registering a converter
Converters are registered in Umbraco via an IComposer.
Umbraco 9+
public class MyCustomerPropertyValueConverterComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.EnterspeedPropertyValueConverters()
.Append<MyCustomPropertyValueConverter>();
}
}
Umbraco 8
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
public class MyCustomerPropertyValueConverterComposer : IUserComposer
{
composition.EnterspeedPropertyValueConverters()
.Append<MyCustomPropertyValueConverter>();
}
Umbraco 7
public class RegisterCustomPropertyValueConverters : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
EnterspeedContext.Current.EnterspeedPropertyValueConverters
.Append<MyEmbeddedContentPropertyValueConverter>();
}
}
Note that the EnterspeedPropertyService will find the converters in the order that they are registered, which means that if you want to replace a default converter with your own, you need to insert your converter like this:
Umbraco 9+
[ComposeAfter(typeof(EnterspeedComposer))]
public class MyCustomerPropertyValueConverterComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.EnterspeedPropertyValueConverters()
.InsertBefore<DefaultTextboxPropertyValueConverter,MyCustomPropertyValueConverter>();
}
}
Umbraco 8
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
public class MyCustomerPropertyValueConverterComposer : IUserComposer
{
composition.EnterspeedPropertyValueConverters()
.InsertBefore<DefaultTextboxPropertyValueConverter,MyCustomPropertyValueConverter>();
}
Umbraco 7
public class RegisterCustomPropertyValueConverters : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
EnterspeedContext.Current.EnterspeedPropertyValueConverters
.InsertBefore<DefaultTextboxPropertyValueConverter, MyCustomTextboxPropertyValueConverter>();
}
}
Default converters
Enterspeed ships with default property value converters for all the built-in property editors that Umbraco ships with out of the box.