Ejemplo n.º 1
0
        //private void NotifyOnPropertyChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs)
        //{
        //    if (PropertyName == propertyChangedEventArgs.PropertyName)
        //    {
        //        Core.Logger.Log($"Property Changed {propertyChangedEventArgs.PropertyName}");
        //        BindingMember.OnPropertyChanged(nameof(BindingMember.Value));
        //    }
        //}

        /// <summary>
        /// Gets a "BindingMember" object for every valid property in an object
        /// </summary>
        /// <param name="value">an object containing properties</param>
        /// <param name="parent">property value for which this property is a child</param>
        /// <returns></returns>
        private static IEnumerable <BindingMember> GetProperties(object value, BindingMember parent = null)
        {
            var settingProperties =
                from p in value.GetType().GetProperties()
                where p != null && p.IsDefined(typeof(SettingAttribute), false)
                select new BindingMember(p, value, parent);

            return(settingProperties);
        }
Ejemplo n.º 2
0
        private static BindingMember GetProperty(object value, string propertyName, BindingMember parent = null)
        {
            var property = value.GetType().GetProperty(propertyName);

            if (property != null && property.IsDefined(typeof(SettingAttribute), false))
            {
                return(new BindingMember(property, value, parent));
            }
            return(null);
        }
Ejemplo n.º 3
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return(null);
            }

            var param = parameter as string;

            if (param != null)
            {
                PropertyName = param;
                var paramBinding = GetProperty(value, param);
                if (paramBinding != null)
                {
                    BindingMember = paramBinding;
                    return(paramBinding);
                }
            }

            var settingProperties = GetProperties(value).ToList();

            //// Flatten Embedded Settings Objects.
            //foreach (var pv in settingProperties.ToList())
            //{
            //    if (pv.Value is IDynamicSettings)
            //    {
            //        Log.Info(LogCategory.Configuration, "Detected Embedded Settings Object {0}", pv.Type);
            //        var childProps = GetProperties(pv.Value, pv).ToList();
            //        //pv.Children.AddRange(childProps);
            //        settingProperties.AddRange(childProps);
            //        settingProperties.Remove(pv);
            //    }
            //}

            var cvs = new CollectionViewSource();

            cvs.Source = settingProperties;
            cvs.GroupDescriptions.Add(new PropertyGroupDescription("Category"));
            return(cvs.View);
        }
Ejemplo n.º 4
0
        private static IEnumerable <BindingMember> GetProperties(object value, BindingMember parent = null)
        {
            var previousExecutionState = BotMain.IsPausedForStateExecution;

            BotMain.IsPausedForStateExecution = false;

            var results = new ConcurrentBag <BindingMember>();

            var props = value.GetType().GetProperties();

            //var interfacePropsNames = new HashSet<string>(value.GetType().GetInterfaces().SelectMany(i => i.GetProperties()).Select(p => p.Name));

            Parallel.ForEach(props, prop =>
            {
                BindingMember bm = null;
                try
                {
                    //if (!interfacePropsNames.Contains(prop.Name))
                    //    return;

                    bm = new BindingMember(prop, value, null, true);
                }
                catch (Exception ex)
                {
                    Core.Logger.Error("PropertyGridConverter Exception: {0}", ex);
                }

                if (bm != null)
                {
                    results.Add(bm);
                }
            });

            BotMain.IsPausedForStateExecution = previousExecutionState;

            return(results.OrderBy(p => p.PropertyName));
        }