public void AssertThatReflectionUtilityCanFindTypesWithSpecificAttribute() { // All classes with Letter attribute var allTypesWithAttribute = new List <Type>() { typeof(B), typeof(D) }; var reflectionTypesOfAWithAttributeLetter = new List <Type>(); reflectionTypesOfAWithAttributeLetter.AddRange(ReflectionUtility.GetAllDerivedTypesOfTypeWithAttribute <A, LetterAttribute>()); Assert.AreEqual(2, reflectionTypesOfAWithAttributeLetter.Count); for (var i = 0; i < allTypesWithAttribute.Count; i++) { Assert.IsTrue(reflectionTypesOfAWithAttributeLetter.Exists(x => x == allTypesWithAttribute[i])); } }
public void AddTypeWithAttribute <T, TV>() where T : class where TV : Attribute { var types = ReflectionUtility.GetAllDerivedTypesOfTypeWithAttribute <T, TV>(false); foreach (var type in types) { if (_ignoreClassTypes.Any(x => type.IsSubclassOf(x) || type == x)) { continue; } if (_ignoreAttributeTypes.Any(x => type.GetCustomAttributes(x, false).Length > 0)) { continue; } Types.Add(type); } }