private static PropertyFilterAttribute [] CreateAllAttributeOptions() { // This iterates over all possible combinations PropertyFilterAttribute [] opts = new PropertyFilterAttribute [16]; for (int i = 0; i < 16; i++) { // Note: This is certainly not an ideal technique for this, but it saves space opts [i] = new PropertyFilterAttribute ((PropertyFilterOptions)i); } return opts; }
/// <summary> /// Match determines if one attribute "matches" another. For /// attributes that store flags, a match may be different from /// an equals. For example, a filter of SetValid matches a /// filter of All, because All is a merge of all filter values. /// </summary> public override bool Match(object value) { PropertyFilterAttribute a = value as PropertyFilterAttribute; if (a == null) { return(false); } return((_filter & a._filter) == _filter); }
//------------------------------------------------------ // // Public Methods // //------------------------------------------------------ #region Public Methods /// <summary> /// Override of Object.Equals that returns true if the filters /// contained in both attributes match. /// </summary> public override bool Equals(object value) { PropertyFilterAttribute a = value as PropertyFilterAttribute; if (a != null && a._filter.Equals(_filter)) { return(true); } return(false); }
public void PropertyFilterAttributeOptionsNoneTest() { PropertyFilterAttribute all = new PropertyFilterAttribute (PropertyFilterOptions.None); bool [] matches = new bool [] { true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, }; ValidateFilterValues (all, matches, (int)PropertyFilterOptions.None, "None"); }
private static void ValidateFilterValues(PropertyFilterAttribute test, bool[] matchResults, int equalsResult, string message) { for (int i = 0; i < 16; i++) { Assert.AreEqual(matchResults[i], test.Match(AllAttributeOptions[i]), message + " - Match - Iteration " + i + ": " + Enum.GetName(typeof(PropertyFilterOptions), (PropertyFilterOptions)i)); Assert.AreEqual (equalsResult == i, test.Equals (AllAttributeOptions [i]), message + " - Equals - Iteration " + i + ": " + Enum.GetName (typeof (PropertyFilterOptions), (PropertyFilterOptions)i)); } }
public void PropertyFilterAttributeOptionsInvalidTest() { PropertyFilterAttribute all = new PropertyFilterAttribute (PropertyFilterOptions.Invalid); bool [] matches = new bool [] { false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, }; ValidateFilterValues (all, matches, (int)PropertyFilterOptions.Invalid, "Invalid"); }
public void PropertyFilterAttributeOptionsSetValuesUnsetValuesValidTest() { PropertyFilterAttribute all = new PropertyFilterAttribute (PropertyFilterOptions.SetValues | PropertyFilterOptions.UnsetValues | PropertyFilterOptions.Valid); bool [] matches = new bool [] { false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, }; ValidateFilterValues (all, matches, (int)(PropertyFilterOptions.SetValues | PropertyFilterOptions.UnsetValues | PropertyFilterOptions.Valid), "SetValues|UnsetValues|Valid"); }
public void PropertyFilterAttributeOptionsInvalidSetValuesUnsetValuesTest() { PropertyFilterAttribute all = new PropertyFilterAttribute (PropertyFilterOptions.Invalid | PropertyFilterOptions.SetValues | PropertyFilterOptions.UnsetValues); bool [] matches = new bool [] { false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, true, }; ValidateFilterValues (all, matches, (int)(PropertyFilterOptions.Invalid | PropertyFilterOptions.SetValues | PropertyFilterOptions.UnsetValues), "Invalid|SetValues|UnsetValues"); }
public void PropertyFilterAttributeOptionsSetValuesTest() { PropertyFilterAttribute all = new PropertyFilterAttribute (PropertyFilterOptions.SetValues); bool [] matches = new bool [] { false, false, true, true, false, false, true, true, false, false, true, true, false, false, true, true, }; ValidateFilterValues (all, matches, (int)PropertyFilterOptions.SetValues, "SetValues"); }