Exemplo n.º 1
0
        public BindingSource <TSource, TTarget> AddFuncBinding(Expression <Func <TSource, object> > sourceGetter, Expression <Func <TTarget, object> > targetProperty)
        {
            PropertyInfo[] targetInfo = PropertyChainFromExp.Get(targetProperty.Body);
            Bridges.Add(new FuncBindingBridge <TSource>(this, sourceGetter, targetInfo));

            return(this);
        }
Exemplo n.º 2
0
        public static string GetFieldName <TRoot>(Expression <Func <TRoot, object> > sourceProperty)
        {
            var           propertyChain = PropertyChainFromExp.Get(sourceProperty);
            List <string> names         = new List <string>();

            foreach (var prop in propertyChain)
            {
                var    attrs = (DisplayAttribute[])prop.GetCustomAttributes(typeof(DisplayAttribute), false);
                string namepart;
                if ((attrs != null) && (attrs.Length > 0))
                {
                    namepart = StringWorks.StringToPascalCase(attrs[0].GetName());
                }
                else
                {
                    namepart = prop.Name;
                }

                foreach (var symb in RemovedSimbols)
                {
                    namepart = namepart.Replace(symb, "");
                }

                names.Add(namepart);
            }
            var name = String.Join(".", names);

            return(name);
        }
Exemplo n.º 3
0
        public void FireChange(params Expression <Func <TWidget, object> >[] targetProperties)
        {
            bool needSetSourceAsBatch = !IsTargetBatchUpdate && targetProperties.Length > 1;

            if (needSetSourceAsBatch)
            {
                IsSourceBatchUpdate = true;
            }
            foreach (var Property in targetProperties)
            {
                var chain = PropertyChainFromExp.Get(Property);
                if (IsTargetBatchUpdate)
                {
                    if (!delayFiredChains.Exists(c => PropertyChainFromExp.GetChainName(chain) == PropertyChainFromExp.GetChainName(c)))
                    {
                        delayFiredChains.Add(chain);
                    }
                }
                else
                {
                    SourceSetValue(
                        PropertyChainFromExp.GetChainName(chain),
                        TargetGetValue(chain)
                        );
                }
            }
            if (needSetSourceAsBatch)
            {
                FinishSourceUpdateBatch();
            }
        }
Exemplo n.º 4
0
        public BindingSource <TSource, TTarget> AddBinding(Expression <Func <TSource, object> > sourceProperty, Expression <Func <TTarget, object> > targetProperty, IValueConverter converter, object converterParameter, System.Globalization.CultureInfo converterCulture)
        {
            PropertyInfo sourceInfo = PropertyUtil.GetPropertyInfo(sourceProperty);

            PropertyInfo[] targetInfo = PropertyChainFromExp.Get(targetProperty.Body);
            Bridges.Add(new BindingBridge(this, sourceInfo, targetInfo, converter, converterParameter, converterCulture));

            return(this);
        }
Exemplo n.º 5
0
        public BindingSource <TSource, TTarget> AddBinding(Expression <Func <TSource, object> > sourceProperty, Expression <Func <TTarget, object> > targetProperty, IValueConverter converter)
        {
            PropertyInfo sourceInfo = PropertyUtil.GetPropertyInfo(sourceProperty);

            PropertyInfo[] targetInfo = PropertyChainFromExp.Get(targetProperty.Body);
            Bridges.Add(new BindingBridge(this, sourceInfo, targetInfo, converter));

            return(this);
        }
Exemplo n.º 6
0
        public BindingObjectSource <TTarget> AddBinding(string sourcePropertyName, Expression <Func <TTarget, object> > targetProperty)
        {
            PropertyInfo sourceInfo = DataSourceObject.GetType().GetProperty(sourcePropertyName);

            if (sourceInfo == null)
            {
                throw new ArgumentException(String.Format("Property {0} not found.", sourcePropertyName));
            }
            PropertyInfo[] targetInfo = PropertyChainFromExp.Get(targetProperty.Body);
            Bridges.Add(new BindingBridge(this, sourceInfo, targetInfo));

            return(this);
        }
Exemplo n.º 7
0
        public BindingObjectSource <TTarget> AddBinding(string sourcePropertyName, Expression <Func <TTarget, object> > targetProperty, IValueConverter converter, object converterParameter, System.Globalization.CultureInfo converterCulture)
        {
            PropertyInfo sourceInfo = DataSourceObject.GetType().GetProperty(sourcePropertyName);

            if (sourceInfo == null)
            {
                throw new ArgumentException(String.Format("Property {0} not found.", sourcePropertyName));
            }

            PropertyInfo[] targetInfo = PropertyChainFromExp.Get(targetProperty.Body);
            Bridges.Add(new BindingBridge(this, sourceInfo, targetInfo, converter, converterParameter, converterCulture));

            return(this);
        }
Exemplo n.º 8
0
        public static string GetCollectionName(Expression <Func <TDoc, IList <TRow> > > sourceProperty)
        {
            var           propertyChain = PropertyChainFromExp.Get(sourceProperty);
            List <string> names         = new List <string>();

            foreach (var prop in propertyChain)
            {
                var    attrs = (DisplayAttribute[])prop.GetCustomAttributes(typeof(DisplayAttribute), false);
                string namepart;
                if ((attrs != null) && (attrs.Length > 0))
                {
                    namepart = StringWorks.StringToPascalCase(attrs[0].GetName());
                }
                else
                {
                    namepart = prop.Name;
                }
                names.Add(namepart);
            }
            var name = String.Join(".", names);

            return(name);
        }
Exemplo n.º 9
0
 public BindingControler(TWidget targetWidget, Expression <Func <TWidget, object> >[] backwardsExp) : this(targetWidget)
 {
     BackwardProperties = backwardsExp.Select(exp =>
                                              String.Join(".", PropertyChainFromExp.Get(exp).Select(p => p.Name)))
                          .ToArray();
 }