Beispiel #1
0
        public IBinder Apply()
        {
            var source = new BindableSource <TSourceValue>(_source, _propertyName, BindingMode.OneWay);
            var binder = new MethodBinder <TSourceValue>(source, _action);

            if (Set == null)
            {
                throw new InvalidOperationException("Binding set is not set");
            }

            Set.Add(binder);
            binder.Start();
            return(binder);
        }
        public IBinder Apply()
        {
            var source = new BindableSource <TSourceValue>(_source, _sourcePropertyName, _mode);

            var sourceValueType = typeof(TSourceValue);
            var targetValueType = typeof(TTargetValue);

            IBinder binder;

            if (sourceValueType == targetValueType)
            {
                if (_converter != null)
                {
                    throw new InvalidOperationException("Converter is redundant if types are the same.");
                }

                var target = new BindableTarget <TSourceValue>(_target, _targetPropertyName, _raiser, _mode);
                binder = new Binder <TSourceValue>(source, target, _mode);
            }
            else
            {
                if (_converter == null)
                {
                    var message = string.Format("Converter is not specified for '{0}:{1}:{2}' and '{3}:{4}:{5}'.",
                                                _source.GetType().Name, _sourcePropertyName, sourceValueType.Name,
                                                _target.GetType().Name, _targetPropertyName, targetValueType.Name);
                    throw new InvalidOperationException(message);
                }

                var target = new BindableTarget <TTargetValue>(_target, _targetPropertyName, _raiser, _mode);
                binder = new Binder <TSourceValue, TTargetValue>(source, target, _converter, _mode);
            }

            if (Set == null)
            {
                throw new InvalidOperationException("Binding set is not set");
            }

            Set.Add(binder);
            binder.Start();
            return(binder);
        }