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); }
private ControlSet FilterByNormalProperty(ControlSet superSet, FilterType filterType, int propertyPartsLength, string propertyName, string propertyRawValue) { Common.AddToLog("checking for property: " + propertyName); ControlSet matchedControls = new ControlSet(); foreach (DependencyObject control in superSet) { PropertyInfo propertyInfo = control.GetType().GetProperty(propertyName); if (propertyInfo != null) { object propertyValue = propertyInfo.GetValue(control, null); if (propertyPartsLength == 1) { object defaultValue = propertyInfo.PropertyType.IsValueType ? Activator.CreateInstance(propertyInfo.PropertyType) : null; if (propertyValue != defaultValue) { Common.AddToLog("matched-by-property-name: " + control.ToString()); matchedControls.Add(control); } } else if (propertyPartsLength == 2) { if (ControlSet.CheckPropertyValue(propertyValue, propertyRawValue, filterType)) { Common.AddToLog("matched-by-property-value: " + control.ToString()); matchedControls.Add(control); } else { Common.AddToLog("not-matched: " + propertyValue + ", " + propertyRawValue); } } } else { Common.AddToLog("property-null: " + propertyName); } } return(matchedControls); }