Пример #1
0
        public ControlSet Execute(ControlSet superSet)
        {
            Common.AddToLog("executing simple-query: " + this.Query);

            if (Type == SimpleSelectorType.None)
            {
                return(new ControlSet());
            }

            //set main controls
            ControlSet mainControls = new ControlSet();

            if (Type == SimpleSelectorType.Universal)
            {
                mainControls.AddRange(superSet);
            }
            else if (Type == SimpleSelectorType.Element)
            {
                Type givenControlType = ControlUtility.ResolveControlType(MainToken.Content);
                if (givenControlType != null)
                {
                    foreach (DependencyObject control in superSet)
                    {
                        //if (givenControlType.IsAssignableFrom(control.GetType()))
                        //if (givenControlType.IsSubclassOf(control.GetType()))
                        //if (givenControlType.FullName.Equals(control.GetType().FullName))
                        if (givenControlType.IsInstanceOfType(control))
                        {
                            mainControls.Add(control);
                        }
                    }
                }
            }

            //apply filter-selectors
            if (this.FilterSelectors.Count == 0)
            {
                return(mainControls);
            }
            else
            {
                foreach (FilterSelector filterSelector in this.FilterSelectors)
                {
                    mainControls = filterSelector.Execute(mainControls);
                }
                return(mainControls);
            }
        }
Пример #2
0
        private ControlSet FilterByDependencyProperty(ControlSet superSet, FilterType filterType, int propertyPartsLength, string propertyNameDescriptor, string propertyRawValue)
        {
            Common.AddToLog("checking for dependency-property: " + propertyNameDescriptor);

            FieldInfo dependencyPropertyField = ControlUtility.ResolveDependencyProperty(propertyNameDescriptor);

            if (dependencyPropertyField != null) //if it is a dependency property
            {
                ControlSet matchedControls = new ControlSet();

                foreach (DependencyObject control in superSet)
                {
                    object dependencyPropertyObject = dependencyPropertyField.GetValue(control);
                    if (dependencyPropertyObject is DependencyProperty)
                    {
                        DependencyProperty dependencyProperty      = (DependencyProperty)dependencyPropertyObject;
                        object             dependencyPropertyValue = control.GetValue(dependencyProperty);
                        if (propertyPartsLength == 1)
                        {
                            object defaultValue = dependencyProperty.GetType().IsValueType ? Activator.CreateInstance(dependencyProperty.GetType()) : null;
                            if (dependencyPropertyValue != defaultValue)
                            {
                                Common.AddToLog("matched by dependency-property-name: " + control.ToString());
                                matchedControls.Add(control);
                            }
                        }
                        else if (propertyPartsLength == 2)
                        {
                            if (ControlSet.CheckPropertyValue(dependencyPropertyValue, propertyRawValue, filterType))
                            {
                                Common.AddToLog("matched by dependency-property-value: " + control.ToString());
                                matchedControls.Add(control);
                            }
                        }
                    }
                }

                return(matchedControls);
            }
            else
            {
                Common.AddToLog("dependency-property-null: " + propertyNameDescriptor);
            }

            return(null);
        }