IsValidType() public method

public IsValidType ( object value ) : bool
value object
return bool
示例#1
0
        /// <summary>
        /// Sets the value of a dependency property.
        /// </summary>
        /// <param name="property">The dependency property whose value is to be set.</param>
        /// <param name="value">The value to set.</param>
        /// <exception cref="System.ArgumentException">Value is of wrong type for this DependencyProperty.</exception>
        public void SetValue(DependencyProperty property, object value)
        {
            if (!property.IsValidType(value))
            {
                throw new ArgumentException("Value is of wrong type for this DependencyProperty.");
            }

            if (property.PropertyType.IsValueType)
            {
                SetValueType(property, value);
            }
            else
            {
                SetValueWeakRef(property, value);
            }
        }
        public void SetValue(DependencyProperty dp, object value)
        {
            if (IsSealed)
            {
                throw new InvalidOperationException("Cannot manipulate property values on a sealed DependencyObject");
            }

            if (!dp.IsValidType(value))
            {
                throw new ArgumentException("value not of the correct type for this DependencyProperty");
            }

            ValidateValueCallback validate = dp.ValidateValueCallback;

            if (validate != null && !validate(value))
            {
                throw new Exception("Value does not validate");
            }
            else
            {
                properties[dp] = value;
            }
        }
示例#3
0
        public void SetValue(DependencyProperty dp, object value)
        {
            if (IsSealed)
                throw new InvalidOperationException ("Cannot manipulate property values on a sealed DependencyObject");

            if (!dp.IsValidType (value))
                throw new ArgumentException ("value not of the correct type for this DependencyProperty");

            ValidateValueCallback validate = dp.ValidateValueCallback;
            if (validate != null && !validate(value))
                throw new Exception("Value does not validate");
            else
                properties[dp] = value;
        }
示例#4
0
        /// <summary>
        /// Sets the value of a dependency property.
        /// </summary>
        /// <param name="property">The dependency property whose value is to be set.</param>
        /// <param name="value">The value to set.</param>
        /// <exception cref="System.ArgumentException">Value is of wrong type for this DependencyProperty.</exception>
        public void SetValue(DependencyProperty property, object value)
        {
            if (!property.IsValidType(value))
                throw new ArgumentException("Value is of wrong type for this DependencyProperty.");

            if (property.PropertyType.IsValueType)
                SetValueType(property, value);
            else
                SetValueWeakRef(property, value);
        }