Ejemplo n.º 1
0
 public override int GetHashCode()
 {
     unchecked
     {
         return((PropertyEditorAlias.GetHashCode() * 397) ^ (Value != null ? Value.GetHashCode() : 0));
     }
 }
        /// <summary>
        /// Gets a value indicating whether the value is of the expected type
        /// for the property, and can be assigned to the property "as is".
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns>True if the value is of the expected type for the property,
        /// and can be assigned to the property "as is". Otherwise, false, to indicate
        /// that some conversion is required.</returns>
        public bool IsPropertyTypeValid(object value)
        {
            // null values are assumed to be ok
            if (value == null)
            {
                return(true);
            }

            // check if the type of the value matches the type from the DataType/PropertyEditor
            var valueType = value.GetType();

            //TODO Add PropertyEditor Type validation when its relevant to introduce

            /*bool isEditorModel = value is IEditorModel;
             * if (isEditorModel && DataTypeControlId != Guid.Empty)
             * {
             *  //Find PropertyEditor by Id
             *  var propertyEditor = PropertyEditorResolver.Current.GetById(DataTypeControlId);
             *
             *  if (propertyEditor == null)
             *      return false;//Throw exception instead?
             *
             *  //Get the generic parameter of the PropertyEditor and check it against the type of the passed in (object) value
             *  Type argument = propertyEditor.GetType().BaseType.GetGenericArguments()[0];
             *  return argument == type;
             * }*/

            if (PropertyEditorAlias.IsNullOrWhiteSpace() == false) // fixme - always true?
            {
                // simple validation using the DatabaseType from the DataTypeDefinition
                // and the Type of the passed in value
                switch (DataTypeDatabaseType)
                {
                // fixme breaking!
                case DataTypeDatabaseType.Integer:
                    return(valueType == typeof(int));

                case DataTypeDatabaseType.Decimal:
                    return(valueType == typeof(decimal));

                case DataTypeDatabaseType.Date:
                    return(valueType == typeof(DateTime));

                case DataTypeDatabaseType.Nvarchar:
                    return(valueType == typeof(string));

                case DataTypeDatabaseType.Ntext:
                    return(valueType == typeof(string));
                }
            }

            // fixme - never reached + makes no sense?
            // fallback for simple value types when no Control Id or Database Type is set
            if (valueType.IsPrimitive || value is string)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 3
0
 protected bool Equals(PropertySlim other)
 {
     return(PropertyEditorAlias.Equals(other.PropertyEditorAlias) && Equals(Value, other.Value));
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Validates the Value from a Property according to its type
        /// </summary>
        /// <param name="value"></param>
        /// <returns>True if valid, otherwise false</returns>
        public bool IsPropertyTypeValid(object value)
        {
            //Can't validate null values, so just allow it to pass the current validation
            if (value == null)
            {
                return(true);
            }

            //Check type if the type of the value match the type from the DataType/PropertyEditor
            Type type = value.GetType();

            //TODO Add PropertyEditor Type validation when its relevant to introduce

            /*bool isEditorModel = value is IEditorModel;
             * if (isEditorModel && DataTypeControlId != Guid.Empty)
             * {
             *  //Find PropertyEditor by Id
             *  var propertyEditor = PropertyEditorResolver.Current.GetById(DataTypeControlId);
             *
             *  if (propertyEditor == null)
             *      return false;//Throw exception instead?
             *
             *  //Get the generic parameter of the PropertyEditor and check it against the type of the passed in (object) value
             *  Type argument = propertyEditor.GetType().BaseType.GetGenericArguments()[0];
             *  return argument == type;
             * }*/

            if (PropertyEditorAlias.IsNullOrWhiteSpace() == false)
            {
                //Find DataType by Id
                //IDataType dataType = DataTypesResolver.Current.GetById(DataTypeControlId);
                //Check if dataType is null (meaning that the ControlId is valid) ?
                //Possibly cast to BaseDataType and get the DbType from there (which might not be possible because it lives in umbraco.cms.businesslogic.datatype) ?

                //Simple validation using the DatabaseType from the DataTypeDefinition and Type of the passed in value
                if (DataTypeDatabaseType == DataTypeDatabaseType.Integer && type == typeof(int))
                {
                    return(true);
                }

                if (DataTypeDatabaseType == DataTypeDatabaseType.Date && type == typeof(DateTime))
                {
                    return(true);
                }

                if (DataTypeDatabaseType == DataTypeDatabaseType.Nvarchar && type == typeof(string))
                {
                    return(true);
                }

                if (DataTypeDatabaseType == DataTypeDatabaseType.Ntext && type == typeof(string))
                {
                    return(true);
                }
            }

            //Fallback for simple value types when no Control Id or Database Type is set
            if (type.IsPrimitive || value is string)
            {
                return(true);
            }

            return(false);
        }
 protected bool Equals(EntityProperty other)
 {
     return(PropertyEditorAlias.Equals(other.PropertyEditorAlias) && string.Equals(Value, other.Value));
 }