Exemplo n.º 1
0
        /// <summary>
        /// When overridden in a derived class, gets the current value of the property on a component.
        /// </summary>
        /// <param name="component">The component with the property for which to retrieve the value.</param>
        /// <returns>
        /// The value of a property for a given component.
        /// </returns>
        public override object GetValue(object component)
        {
            // Have the property bag raise an event to get the current value of the property.
            PropertySpecificationEventArgs e = new PropertySpecificationEventArgs(Specification, null);

            ContainingBag.OnGetValue(e);
            if (Specification != null)
            {
                if (e.Value == null)
                {
                    if (Specification.DefaultValue != null)
                    {
                        e.Value = Specification.DefaultValue;
                    }
                }
                else
                {
                    if (Specification.PropertyType.IsEnum)
                    {
                        Trap.trap();
                        e.Value = Enum.ToObject(Specification.PropertyType, e.Value);
                    }
                }
            }
            return(e.Value);
        }
Exemplo n.º 2
0
        /// <summary>
        /// When overridden in a derived class, sets the value of the component to a different value.
        /// </summary>
        /// <param name="component">The component with the property value that is to be set.</param>
        /// <param name="value">The new value.</param>
        public override void SetValue(object component, object value)
        {
            // Have the property bag raise an event to set the current value of the property.
            object valueToUse = value;

            if (Specification != null)
            {
                if (Specification.PropertyType == typeof(string))
                {
                    if (Specification.ConvertEmptyStringToNull && ((valueToUse as string) == string.Empty))
                    {
                        Trap.trap();
                        valueToUse = null;
                    }
                }
                else
                {
                    if (Specification.PropertyType.IsEnum)
                    {
                        Trap.trap();
                        valueToUse = Convert.ToInt32(valueToUse);
                    }
                }
            }
            PropertySpecificationEventArgs e = new PropertySpecificationEventArgs(Specification, valueToUse);

            ContainingBag.OnSetValue(e);
        }
 /// <summary>
 /// Raises the SetValue event, if ValueGetterFunc is left null, otherwise it will call ValueGetterFunc instead.
 /// </summary>
 /// <param name="e">A PropertySpecEventArgs that contains the event data.</param>
 protected internal virtual void OnSetValue(PropertySpecificationEventArgs e)
 {
     if (this.ValueSetterFunc == null)
     {
         SetValue?.Invoke(this, e);
     }
     else
     {
         Trap.trap();
         this.ValueSetterFunc(e.Property.Name, e.Value);
     }
 }