コード例 #1
0
        public BindingManager <TViewModel> Bind <T>(Expression <Func <TViewModel, T> > sourceExpr, Action <T> setterDelegate)
        {
            if (!(sourceExpr.Body is MemberExpression member))
            {
                throw new ArgumentException($"Expression '{sourceExpr.Name}' refers to a method, not a property.");
            }

            var propInfo = member.Member as PropertyInfo;

            if (propInfo == null)
            {
                throw new ArgumentException($"Expression '{sourceExpr.Name}' refers to a field, not a property.");
            }

            if (propInfo.ReflectedType == null ||
                typeof(TViewModel) != propInfo.ReflectedType &&
                !typeof(TViewModel).IsSubclassOf(propInfo.ReflectedType))
            {
                throw new ArgumentException(
                          $"Expresion '{sourceExpr}' refers to a property that is not from type {typeof(TViewModel).Name}.");
            }

            var sourceGetter = sourceExpr.Compile();

            PropertyBindings.Add(propInfo.Name, new PropertyChangedHandler <TViewModel>(SynchronizationContext.Current,
                                                                                        vm =>
            {
                var val = sourceGetter.Invoke(vm);
                setterDelegate.Invoke(val);
            }));

            return(this);
        }
コード例 #2
0
 public ActivityInfo AddPropertyBinding([NotNull] PropertyBindingInfo binding)
 {
     PropertyBindings.Add(binding.NotNull());
     return(this);
 }