Пример #1
0
        /// <summary>
        /// Gets the marked methods.
        /// </summary>
        /// <param name="reflectionNode">The reflection node.</param>
        /// <param name="markerInterface">The marker interface.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        private IEnumerable <MarkedNode> GetMarkedMethods(ReflectionNode reflectionNode, ITypeDefOrRef markerInterface, WeavingContext context)
        {
            var ancestorsToChildren = reflectionNode.GetAncestorsToDescendants().ToArray();

            return(from node in ancestorsToChildren
                   where node.Method is not null
                   let allMakersNode = new MarkedNode(node, GetAllMarkers(node, markerInterface, context).Select(t => t.Item2))
                                       where allMakersNode.Definitions.Any() && IsIncludedByPointcut(allMakersNode, context) //&& !IsDeclaredByValue(node)
                                       let includedMarkersNode = new MarkedNode(node, allMakersNode.Definitions.Where(d => IsIncludedByNode(d, node, context)))
                                                                 where includedMarkersNode.Definitions.Any()
                                                                 select includedMarkersNode);
        }
Пример #2
0
        /// <summary>
        /// Gets all attributes that implement the given advice interface
        /// </summary>
        /// <param name="reflectionNode">The reflection node.</param>
        /// <param name="markerInterface">The advice interface.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        private IEnumerable <Tuple <ReflectionNode, MarkerDefinition> > GetAllMarkers(ReflectionNode reflectionNode, ITypeDefOrRef markerInterface, WeavingContext context)
        {
            var markers = reflectionNode.GetAncestorsToDescendants()
                          .Select(n => new { Node = n, Attributes = n.CustomAttributes })
                          .SelectMany(n => n.Attributes.Select(a => new { Node = n.Node, Attribute = a })
                                      .Where(a => !a.Attribute.AttributeType.DefinitionAssembly.IsSystem())
                                      .Select(a => new { Node = a.Node, Type = ResolveTypeOrGenericDefinition(a.Attribute.AttributeType) })
                                      .Where(t => IsMarker(t.Type, markerInterface)))
                          .Select(t => Tuple.Create(t.Node, GetMarkerDefinition(t.Type, context)));

            return(markers);
        }
Пример #3
0
        /// <summary>
        /// Gets all attributes that implement the given advice interface
        /// </summary>
        /// <param name="reflectionNode">The reflection node.</param>
        /// <param name="markerInterface">The advice interface.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        private IEnumerable <MarkerDefinition> GetAllMarkers(ReflectionNode reflectionNode, ITypeDefOrRef markerInterface, WeavingContext context)
        {
            var markers = reflectionNode.GetAncestorsToDescendants()
                          .SelectMany(n => n.CustomAttributes
                                      .Where(a => !a.AttributeType.DefinitionAssembly.IsSystem())
                                      .SelectMany(a => ResolveTypeOrGenericDefinition(a.AttributeType).GetSelfAndParents())
                                      .Where(t => IsMarker(t, markerInterface)))
                          .Distinct()
                          .Select(t => GetMarkerDefinition(t, context));

            return(markers);
        }