public void Find_Classes_With_Attribute() { var typeFinder = new TypeFinder(GetTestProfilingLogger()); var typesFound = typeFinder.FindClassesWithAttribute <TreeAttribute>(_assemblies); Assert.AreEqual(0, typesFound.Count()); // 0 classes in _assemblies are marked with [Tree] typesFound = typeFinder.FindClassesWithAttribute <TreeAttribute>(new[] { typeof(UmbracoContext).Assembly }); Assert.AreEqual(22, typesFound.Count()); // + classes in Umbraco.Web are marked with [Tree] }
public void Find_Classes_With_Attribute() { var typeFinder = new TypeFinder(Mock.Of <ILogger <TypeFinder> >(), new DefaultUmbracoAssemblyProvider(GetType().Assembly, NullLoggerFactory.Instance)); IEnumerable <Type> typesFound = typeFinder.FindClassesWithAttribute <TreeAttribute>(_assemblies); Assert.AreEqual(0, typesFound.Count()); // 0 classes in _assemblies are marked with [Tree] typesFound = typeFinder.FindClassesWithAttribute <TreeAttribute>(new[] { typeof(TreeAttribute).Assembly }); Assert.AreEqual(23, typesFound.Count()); // + classes in Umbraco.Web are marked with [Tree] typesFound = typeFinder.FindClassesWithAttribute <TreeAttribute>(); Assert.AreEqual(23, typesFound.Count()); // + classes in Umbraco.Web are marked with [Tree] }
public void Benchmark_New_Finder() { using (DisposableTimer.TraceDuration <TypeFinderTests>("Starting test", "Finished test")) { using (DisposableTimer.TraceDuration <TypeFinderTests>("Starting FindClassesOfType", "Finished FindClassesOfType")) { for (var i = 0; i < 1000; i++) { Assert.Greater(TypeFinder.FindClassesOfType <DisposableObject>(_assemblies).Count(), 0); } } using (DisposableTimer.TraceDuration <TypeFinderTests>("Starting FindClassesOfTypeWithAttribute", "Finished FindClassesOfTypeWithAttribute")) { for (var i = 0; i < 1000; i++) { Assert.Greater(TypeFinder.FindClassesOfTypeWithAttribute <TestEditor, MyTestAttribute>(_assemblies).Count(), 0); } } using (DisposableTimer.TraceDuration <TypeFinderTests>("Starting FindClassesWithAttribute", "Finished FindClassesWithAttribute")) { for (var i = 0; i < 1000; i++) { Assert.Greater(TypeFinder.FindClassesWithAttribute <XsltExtensionAttribute>(_assemblies).Count(), 0); } } } }
public void Build(IContainer container) { var providerName = ConfigurationManager.ConnectionStrings["umbracoDbDSN"].ProviderName; var provider = TypeFinder.FindClassesWithAttribute <SqlSyntaxProviderAttribute>() .FirstOrDefault(p => p.GetCustomAttribute <SqlSyntaxProviderAttribute>(false).ProviderName == providerName); if (provider == null) { throw new FileNotFoundException(string.Format("Unable to find SqlSyntaxProvider that is used for the provider type '{0}'", providerName)); } SqlSyntaxContext.SqlSyntaxProvider = (ISqlSyntaxProvider)Activator.CreateInstance(provider); container.Register <Func <string, ISqlCeEngine> >(() => s => new SqlCeEngineWrapper(s)); }
public static IEnumerable <MethodInfo> GetCachedExtensions <TAttributeType>(Assembly fromAssembly) where TAttributeType : Attribute { var cacheKey = new ScannerCacheKey { AttributeScannedFor = typeof(TAttributeType), ScannedAssembly = fromAssembly }; var methods = _methodCache .GetOrAdd(cacheKey, x => { var withAttribute = TypeFinder.FindClassesWithAttribute <DynamicExtensionsAttribute>(fromAssembly.AsEnumerableOfOne(), false); var allMethods = withAttribute.SelectMany(type => type.GetMethods()); var allMethodsWithAttribute = allMethods.Where(method => method.GetCustomAttributes <TAttributeType>(false).Any()).ToArray(); return(allMethodsWithAttribute); }); return(methods); }
public void Find_Classes_With_Attribute() { var typesFound = TypeFinder.FindClassesWithAttribute <RestExtensionAttribute>(_assemblies); Assert.AreEqual(1, typesFound.Count()); }