Exemple #1
0
        public static object TryInvoke <TOwner, TValue>(
            this PropertyCoerce <TOwner, TValue> @this,
            DependencyObject dependencyObject,
            object baseValue)
            where TOwner : DependencyObject
        {
            if (@this == null)
            {
                return((TValue)baseValue);
            }

            if (!(dependencyObject is TOwner))
            {
                throw new InvalidCastException(
                          $"The \'dependencyObject\' argument must be of type \'{typeof(TOwner).Name}\'.");
            }
            var owner = (TOwner)dependencyObject;

            if (!(baseValue is TValue))
            {
                throw new InvalidCastException(
                          $"The \'baseValue\' argument must be of type \'{typeof(TValue).Name}\'.");
            }
            var value = (TValue)baseValue;

            return(@this.Invoke(owner, value));
        }
Exemple #2
0
 public static object TryInvoke <D, T>(this PropertyCoerce <D, T> i, DependencyObject dependencyObject, object baseValue) where D : DependencyObject
 {
     if (i == null)
     {
         return((T)baseValue);
     }
     return(i.Invoke((D)dependencyObject, (T)baseValue));
 }