예제 #1
0
        /// <summary>
        /// Détermine si cette propriété a été initialisée
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns>
        ///     <c>true</c> if the specified element has value; otherwise, <c>false</c>.
        /// </returns>
        public bool HasValue(ICustomizableElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            DependencyProperty property = element.GetStrategyCustomProperty(_strategyId, _name, false);

            return(property != null && property.Value != null);
        }
예제 #2
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;
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Tries the get value.
        /// </summary>
        /// <param name="self">The self.</param>
        /// <param name="element">The element.</param>
        /// <param name="strategyId">The strategy id.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        protected static bool TryGetValue(IDependencyProperty self, ICustomizableElement element, string strategyId,
                                          string propertyName, out T value)
        {
            // Recherche si cette valeur est dans le modèle
            DependencyProperty property = element.GetStrategyCustomProperty(strategyId, propertyName, false);

            if (property != null)
            {
                if (property.Value != null) // Pas initialisée
                {
                    value = property.Value.GetValue <T>(self);
                    //    if (SerializationUtilities.TryGetValue<T>(SerializationUtilities.UnescapeXmlString(property.Value), out value))
                    if (value != null)
                    {
                        return(true);
                    }
                }
            }
            value = default(T);
            return(false);
        }