Esempio 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);
        }
Esempio 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);
        }
Esempio 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();
            }
        }
Esempio 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);
        }
Esempio 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);
        }
Esempio 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);
        }
Esempio 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);
        }
Esempio 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);
        }
Esempio 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();
 }