private void DefineAttributes() { bool hasAddedAttribute; HashSet <RegionAttribute> attributesToSkip = new HashSet <RegionAttribute>(); // Since there are attributes that have dependencies on other attributes, we might need to test each attribute more than once. do { hasAddedAttribute = false; foreach (RegionAttribute r in RegionAttribute.Attributes.Values) { if (!attributesToSkip.Contains(r) && r.Assignable(this)) { Info.AddAttribute(r.GetInstanceForRegion(this)); hasAddedAttribute = true; attributesToSkip.Add(r); // If the attribute has already been added then we don't need it to test it again } } }while (hasAddedAttribute); // Repeat if at least one new attribute was added in the previous loop attributesToSkip.Clear(); // Now validate secondary attributes do { hasAddedAttribute = false; foreach (RegionAttribute r in RegionAttribute.SecondaryAttributes.Values) { if (!attributesToSkip.Contains(r) && r.Assignable(this)) { Info.AddAttribute(r.GetInstanceForRegion(this)); hasAddedAttribute = true; attributesToSkip.Add(r); // If the attribute has already been added then we don't need it to test it again } } }while (hasAddedAttribute); // Repeat if at least one new attribute was added in the previous loop }