public AspectDefinition[] Match(Type targetType, AspectDefinitionCollection aspects) { // TODO: think about caches here... ArrayList list = new ArrayList(); foreach (AspectDefinition aspect in aspects) { IClassMatcher matcher = ObtainClassMatcher(aspect); if (matcher.Match(targetType, aspect)) { list.Add(aspect); } } return((AspectDefinition[])list.ToArray(typeof(AspectDefinition))); }
protected virtual IClassMatcher ObtainCustomMatcher(TargetTypeDefinition target) { Type customType = target.CustomMatcherType.ResolvedType; IClassMatcher matcher = GetCustomMatcherFromCache(customType); try { matcher = (IClassMatcher)Activator.CreateInstance(customType); } catch (InvalidCastException ex) { throw new MatcherException("Error trying to cast your custom class matcher to IClassMatcher", ex); } catch (Exception ex) { throw new MatcherException("Error trying to instantiate your custom class matcher", ex); } RegisterMatcherInCache(matcher, customType); return(matcher); }
private void RegisterMatcherInCache(IClassMatcher matcher, Type customType) { _customMatcherCache[customType] = matcher; }