Exemplo n.º 1
0
            protected override object[] ConvertBack(object value, Type[] targetTypes)
            {
                if (treeInfo.BackExpr == null && !BindingCalculator.IsSimpleExpr(treeInfo.Expr))
                {
                    errorHandler.Throw(ErrorHelper.Err101_TwoWay(), null);
                }
                if (!isBackConvesionInitialized)
                {
                    Type valueType = value.Return(x => x.GetType(), () => null);
                    calculator.InitBack(valueType ?? backConversionType);
                    isBackConvesionInitialized = true;
                }
                List <object> res = new List <object>();

                foreach (var op in calculator.Operands)
                {
                    if (!op.IsTwoWay || op.BackConverter == null)
                    {
                        res.Add(value);
                    }
                    else
                    {
                        res.Add(op.BackConverter(new object[] { value }));
                    }
                }
                return(res.ToArray());
            }
Exemplo n.º 2
0
 protected override object GetProvidedValue()
 {
     if (Mode == BindingMode.Default && TreeInfo.BackExpr == null &&
         Calculator.Operands.Count() == 0)
     {
         ActualMode = BindingMode.OneWay;
     }
     if ((ActualMode == BindingMode.TwoWay || ActualMode == BindingMode.OneWayToSource) &&
         TreeInfo.BackExpr == null)
     {
         if (BindingCalculator.IsSimpleExpr(TreeInfo.Expr))
         {
             Calculator.Operands.FirstOrDefault().Do(x => x.SetMode(true));
         }
         else
         {
             ErrorHandler.Throw(ErrorHelper.Err101_TwoWay(), null);
         }
     }
     if (IsInSetter(TargetProvider) || TargetPropertyType == typeof(BindingBase))
     {
         return(CreateBinding());
     }
     return(CreateBinding().ProvideValue(ServiceProvider));
 }