/// <summary>
 /// Converts the given object to the type of this converter, using the specified context and culture information.
 /// </summary>
 /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context.</param>
 /// <param name="culture">The <see cref="T:System.Globalization.CultureInfo"></see> to use as the current culture.</param>
 /// <param name="value">The <see cref="T:System.Object"></see> to convert.</param>
 /// <returns>
 /// An <see cref="T:System.Object"></see> that represents the converted value.
 /// </returns>
 /// <exception cref="T:System.NotSupportedException">The conversion cannot be performed. </exception>
 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
 {
     if (value is string)
     {
         DependencyPropertyValue v = new DependencyPropertyValue();
         v.Value = (string)value;
         return(v);
     }
     return(base.ConvertFrom(context, culture, value));
 }
 /// <summary>
 /// Converts to.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="culture">The culture.</param>
 /// <param name="value">The value.</param>
 /// <param name="destType">Type of the dest.</param>
 /// <returns></returns>
 public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
 {
     if (destType == typeof(string))
     {
         DependencyPropertyValue v = value as DependencyPropertyValue;
         if (v != null)
         {
             v.Value = v.ToString();
             return(v.Value);
         }
     }
     return(base.ConvertTo(context, culture, value, destType));
 }
Пример #3
0
        /// <summary>
        /// Mise à jour d'un paramètre personnalisé
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="value">The value.</param>
        public virtual void SetValue(ICustomizableElement instance, T value)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }

            bool isDefaultValue = false;
            // HasDefaultValue && DefaultValue.Equals(value);// (Voir ShouldSerializeValue property) || (_shouldSerializeValueDelegate != null && !_shouldSerializeValueDelegate(value));
            DependencyProperty property = instance.GetStrategyCustomProperty(_strategyId, _name, !isDefaultValue);

            if (property != null && value != null)
            {
                Transaction transaction =
                    ((ModelElement)instance).Store.TransactionManager.BeginTransaction("Set custom value");
                try
                {
                    //property.Value = SerializationUtilities.GetString<T>(value);
                    DependencyPropertyValue dpv = new DependencyPropertyValue();
                    dpv.SetValue(this, value);
                    property.Value = dpv;

                    transaction.Commit();
                }
                catch (ArgumentOutOfRangeException exception)
                {
                    if (transaction.IsActive)
                    {
                        transaction.Rollback();
                    }
                    throw;
                }
                catch (Exception)
                {
                    if (transaction.IsActive)
                    {
                        transaction.Rollback();
                    }
                    throw;
                }
            }
        }