日期:2014-05-20 浏览次数:21099 次
private static IEnumerable<TestCaseType> GetTestCases(bool selectAllTestCase) { var tm = DateTime.Now.AddDays(-7); return from asm in AppDomain.CurrentDomain.GetAssemblies() let types = asm.GetTypes() where asm.GetReferencedAssemblies().Any(asm2 => asm2.FullName == typeof(Tests).Assembly.FullName) from t in types from m in t.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static) let pa = new { attrs = m.GetCustomAttributes(typeof(TestCaseAttribute), true).OfType<TestCaseAttribute>().Where(x => x.TimeStamp <= DateTime.Now), } where (selectAllTestCase || pa.attrs.Any(x => x.TimeStamp >= tm)) let pb = new { attr = pa.attrs.FirstOrDefault(x => x.GetType() == typeof(TestCaseAttribute)), method = m } where m.ReturnType == typeof(void) && m.GetParameters().Length == 0 && !m.GetCustomAttributes(typeof(StopSupportAttribute), true).OfType<StopSupportAttribute>().Any(at => at.TimeStamp <= DateTime.Now) && pb.attr != null select new TestCaseType { attr = pb.attr, proc = (TestCaseDelegate)Delegate.CreateDelegate(typeof(TestCaseDelegate), m) }; }
------解决方案--------------------
虽然不是很明白楼上的代码,但是膜拜之情,油然而生。
------解决方案--------------------