using System; using AutoMapper; using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; using Umbraco.Web.Models.ContentEditing; namespace Umbraco.Web.Models.Mapping { /// /// Creates a base generic ContentPropertyBasic from a Property /// /// internal class ContentPropertyBasicConverter : TypeConverter where T : ContentPropertyBasic, new() { /// /// Assigns the PropertyEditor, Id, Alias and Value to the property /// /// /// protected override T ConvertCore(Property property) { var editor = PropertyEditorResolver.Current.GetById(property.PropertyType.DataTypeId); if (editor == null) { //TODO: Remove this check as we shouldn't support this at all! var legacyEditor = DataTypesResolver.Current.GetById(property.PropertyType.DataTypeId); if (legacyEditor == null) { throw new NullReferenceException("The property editor with id " + property.PropertyType.DataTypeId + " does not exist"); } var legacyResult = new T { Id = property.Id, Value = property.Value == null ? "" : property.Value.ToString(), Alias = property.Alias }; return legacyResult; } var result = new T { Id = property.Id, Value = editor.ValueEditor.FormatDataForEditor(property.Value), Alias = property.Alias }; result.PropertyEditor = editor; return result; } } }