Exemplo n.º 1
0
        private ValueStorageType MapDatabaseType(DataTypeSave source)
        {
            if (!_propertyEditors.TryGet(source.EditorAlias, out var editor))
            {
                throw new InvalidOperationException($"Could not find property editor \"{source.EditorAlias}\".");
            }

            // TODO: what about source.PropertyEditor? can we get the configuration here? 'cos it may change the storage type?!
            var valueType = editor.GetValueEditor().ValueType;

            return(ValueTypes.ToStorageType(valueType));
        }
        /// <summary>
        /// A method used to format the database value to a value that can be used by the editor
        /// </summary>
        /// <param name="property"></param>
        /// <param name="dataTypeService"></param>
        /// <param name="culture"></param>
        /// <param name="segment"></param>
        /// <returns></returns>
        /// <remarks>
        /// The object returned will always be a string and if the database type is not a valid string type an exception is thrown
        /// </remarks>
        public override object ToEditor(Property property, IDataTypeService dataTypeService, string culture = null, string segment = null)
        {
            var val = property.GetValue(culture, segment);

            if (val == null)
            {
                return(string.Empty);
            }

            switch (ValueTypes.ToStorageType(ValueType))
            {
            case ValueStorageType.Ntext:
            case ValueStorageType.Nvarchar:
                return(val.ToString());

            case ValueStorageType.Integer:
            case ValueStorageType.Decimal:
            case ValueStorageType.Date:
            default:
                throw new InvalidOperationException("The " + typeof(TextOnlyValueEditor) + " can only be used with string based property editors");
            }
        }