Ejemplo n.º 1
0
        public void AddItems <TItem>(ComboBox control, Expression <Func <TDocument, TItem> > property, IEnumerable <TItem> items) where TItem : class
        {
            PropertyInfo             pi          = GetProperty(property);
            Func <TDocument, string> setProperty = (doc) =>
            {
                pi.SetValue(doc, (control.SelectedItem as TItem));
                return(pi.Name);
            };

            var func = property.Compile();
            Action <TDocument> setControl = (doc) =>
            {
                ComboBoxExtensions.SetItem(control, func.Invoke(doc));
            };

            AddItems(control, setProperty, setControl, items);
        }
Ejemplo n.º 2
0
        public void AddEnum <TEnum>(ComboBox control, Expression <Func <TDocument, TEnum> > property)
        {
            PropertyInfo             pi          = GetProperty(property);
            Func <TDocument, string> setProperty = (doc) =>
            {
                pi.SetValue(doc, (control.SelectedItem as ListItem <TEnum>).Value);
                return(pi.Name);
            };

            var func = property.Compile();
            Action <TDocument> setControl = (doc) =>
            {
                ComboBoxExtensions.SetValue(control, func.Invoke(doc));
            };

            AddEnum <TEnum>(control, setProperty, setControl);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Fills a combo box from TItem keys of a dictionary, mapping to corresponding TValues that are bound to the document
        /// </summary>
        public void AddItems <TValue, TItem>(ComboBox control, Expression <Func <TDocument, TValue> > property, Dictionary <TValue, TItem> itemDictionary) where TItem : class
        {
            var pi = GetProperty(property);
            Func <TDocument, string> setProperty = (doc) =>
            {
                var reverseDictionary = itemDictionary.ToDictionary(kp => kp.Value, kp => kp.Key);
                pi.SetValue(doc, reverseDictionary[control.GetItem <TItem>()]);
                return(pi.Name);
            };

            var func = property.Compile();
            Action <TDocument> setControl = (doc) =>
            {
                var value = func.Invoke(doc);
                ComboBoxExtensions.SetItem(control, itemDictionary[value]);
            };

            AddItems(control, setProperty, setControl, itemDictionary.Select(kp => kp.Value));
        }