Пример #1
0
        public Binding Build()
        {
            if (_targetRoot == null || _sourceRoot == null)
            {
                throw new ArgumentException("targetRoot or sourceRoot are null");
            }
            if (_targetPropertyExpression == null || _sourcePropertyExpression == null)
            {
                throw new ArgumentException("targetPropertyExpression or sourcePropertyExpression are null");
            }
            var sourceMember  = BindingExtension.GetMemberInfo(_sourcePropertyExpression);
            var sourceTrigger = new Trigger(_sourceRoot, sourceMember);

            var targetMember  = BindingExtension.GetMemberInfo(_targetPropertyExpression);
            var targetTrigger = new Trigger(_targetRoot, targetMember);

            var binding = new Binding(sourceTrigger, targetTrigger);

            binding.SubscribeSourceFromChangeNotificationEvent(_customSourceEventName, _isSourcePropertyChangeEnable);
            if (_bindingMode == BindingMode.TwoWay)
            {
                binding.SubscribeTargetFromChangeNotificationEvent(_customTargetEventName, _isTargetPropertyChangeEnable);
            }
            return(binding);
        }
Пример #2
0
        public BindingBuilder SetTarget <TTarget>(Expression <Func <TTarget> > targetExpression)
        {
            var member = targetExpression.Body as MemberExpression;

            if (member == null)
            {
                throw new ArgumentException("targetExpression is not memberExpression");
            }
            _targetPropertyExpression = targetExpression;
            return(SetTarget(BindingExtension.EvalTarget(member), targetExpression));
        }
Пример #3
0
        public void Subscribe(string eventName, EventHandler handler)
        {
            var       type = Target.GetType();
            EventInfo ev   = BindingExtension.GetEvent(type, eventName);

            if (ev == null)
            {
                return;
            }
            var isClassicHandler =
                typeof(EventHandler).GetTypeInfo().IsAssignableFrom(ev.EventHandlerType.GetTypeInfo());
            var eventHandler = isClassicHandler
                ? handler
                : BindingExtension.CreateGenericEventHandler(ev, () => handler(null, EventArgs.Empty));

            ev.AddEventHandler(Target, eventHandler);
            Events.Add(eventName, new Tuple <EventInfo, Delegate>(ev, eventHandler));
        }
Пример #4
0
 public bool SetValue(object value)
 {
     return(BindingExtension.SetValue(Target, Member, value));
 }
Пример #5
0
 public object GetValue()
 {
     return(BindingExtension.GetValue(Target, Member));
 }