private void SetPropertyValueOnModel(object objectInstance, PropertyRegistration registration, object umbracoStoredValue) { if (registration.DataType.ConverterType != null) { IDataTypeConverter converter = (IDataTypeConverter)Activator.CreateInstance(registration.DataType.ConverterType); var val = converter.Create(umbracoStoredValue, x => CodeFirstModelContext.MoveNextContext(x, registration)); if (val != null) { CodeFirstModelContext.MoveNextContext(val, registration); var attr = registration.Metadata.GetCodeFirstAttribute <ContentPropertyAttribute>(); if (attr != null && attr is IDataTypeRedirect) { val = (attr as IDataTypeRedirect).GetRedirectedValue(val); if (val != null) { //Keep a second context so wrapped types can still find their property //Will add nothing if the Redirector registered a context already (e.g. called ConvertToModel to create the value). //Hopefully said redirector passed in a parent context so the converted value can still find its way back here. CodeFirstModelContext.MoveNextContext(val, registration); } } registration.Metadata.SetValue(objectInstance, val); } } else if (umbracoStoredValue != null) { //Context currently not supported for PEVCs - many are value types, very unlikely to have unique hashes for all values in a request context, none except custom ones would have //code to use the context anyway. registration.Metadata.SetValue(objectInstance, umbracoStoredValue); } }