Esempio n. 1
0
        public void Test_TypesHelper_FindAllDerivedTypesInThisAssembly()
        {
            List <Type> types = TypesHelper.FindAllDerivedTypes <MemoryStream>(Assembly.GetExecutingAssembly());

            Assert.True(types.Any(x => x.IsAssignableFrom(typeof(TestClass))), "testClass not noted as a descendent of MemoryStream");

            List <Type> types2 = TypesHelper.FindAllDerivedTypes <List <object> >(Assembly.GetExecutingAssembly());

            Assert.False(types2.Any(x => x.IsAssignableFrom(typeof(TestClass))), "testClass incorrectly noted as a descendent of List<>");
        }
Esempio n. 2
0
        /// <summary>
        /// Locate all value matcher classes and add them to the value matchers list using reflection (or just manually as below)
        /// </summary>
        private static Dictionary <string, TAGValueMatcher> InitialiseValueMatchers()
        {
            // Get all the value matcher classes that exist in the assembly. These are all classes that
            // descend from TAGValueMatcher
            var matchers = TypesHelper.FindAllDerivedTypes <TAGValueMatcher>();

            var valueMatchers = new Dictionary <string, TAGValueMatcher>();

            // Iterate through those types and create each on in turn, query the TAG types from it that the matcher supports and
            // then register the value matcher instance against those TAGs to allow the TAG file processor to locate matcher for TAGS
            foreach (var t in matchers)
            {
                var matcher = (TAGValueMatcher)Activator.CreateInstance(t);

                foreach (string tag in matcher.MatchedValueTypes())
                {
                    valueMatchers.Add(tag, matcher);
                }
            }

            return(valueMatchers);
        }
Esempio n. 3
0
        public void Test_TypesHelper_FindAllDerivedTypes_Fail()
        {
            List <Type> types = TypesHelper.FindAllDerivedTypes <MemoryStream>();

            Assert.False(types.Any(x => x.IsAssignableFrom(typeof(TestClass))), "testClass noted as a descendent of MemoryStream (defined in different assembly)");
        }