/// <summary> /// A method to deserialize the string value that has been saved in the content editor /// to an object to be stored in the database. /// </summary> /// <param name="editorValue"></param> /// <param name="currentValue"> /// The current value that has been persisted to the database for this editor. This value may be usesful for /// how the value then get's deserialized again to be re-persisted. In most cases it will probably not be used. /// </param> /// <returns></returns> /// <remarks> /// By default this will attempt to automatically convert the string value to the value type supplied by ValueType. /// /// If overridden then the object returned must match the type supplied in the ValueType, otherwise persisting the /// value to the DB will fail when it tries to validate the value type. /// </remarks> public virtual object ConvertEditorToDb(ContentPropertyData editorValue, object currentValue) { //if it's json but it's empty json, then return null if (ValueType.InvariantEquals(PropertyEditorValueTypes.Json) && editorValue.Value != null && editorValue.Value.ToString().DetectIsEmptyJson()) { return(null); } var result = TryConvertValueToCrlType(editorValue.Value); if (result.Success == false) { LogHelper.Warn <PropertyValueEditor>("The value " + editorValue.Value + " cannot be converted to the type " + GetDatabaseType()); return(null); } return(result.Result); }
/// <summary> /// A method to deserialize the string value that has been saved in the content editor /// to an object to be stored in the database. /// </summary> /// <param name="editorValue"></param> /// <param name="currentValue"> /// The current value that has been persisted to the database for this editor. This value may be useful for /// how the value then get's deserialized again to be re-persisted. In most cases it will probably not be used. /// </param> /// <param name="languageId"></param> /// <param name="segment"></param> /// <returns></returns> /// <remarks> /// By default this will attempt to automatically convert the string value to the value type supplied by ValueType. /// /// If overridden then the object returned must match the type supplied in the ValueType, otherwise persisting the /// value to the DB will fail when it tries to validate the value type. /// </remarks> public virtual object FromEditor(ContentPropertyData editorValue, object currentValue) { //if it's json but it's empty json, then return null if (ValueType.InvariantEquals(ValueTypes.Json) && editorValue.Value != null && editorValue.Value.ToString().DetectIsEmptyJson()) { return(null); } var result = TryConvertValueToCrlType(editorValue.Value); if (result.Success == false) { StaticApplicationLogging.Logger.LogWarning("The value {EditorValue} cannot be converted to the type {StorageTypeValue}", editorValue.Value, ValueTypes.ToStorageType(ValueType)); return(null); } return(result.Result); }