Example #1
0
        /// <summary>
        /// Rewrites all members in the document.
        /// </summary>
        public SyntaxNode Process(SyntaxNode syntax, ProcessorContext context)
        {
            var virtualEvents = new HashSet <string>();
            var semantic      = context.Compilation.GetSemanticModel(syntax.SyntaxTree);

            if (semantic != null)
            {
                var events = new EventVisitor();
                events.Visit(syntax);

                foreach (var symbol in events.Types.SelectMany(type => semantic
                                                               .LookupNamespacesAndTypes(type.Span.Start, name: type.Identifier.ValueText)
                                                               .OfType <INamedTypeSymbol>()).Where(x => x != null))
                {
                    var baseType = symbol.BaseType;
                    while (baseType != null)
                    {
                        foreach (var e in baseType.GetMembers().OfType <IEventSymbol>().Where(e => e.IsVirtual))
                        {
                            virtualEvents.Add(e.Name);
                        }

                        baseType = baseType.BaseType;
                    }
                }
            }

            return(syntax = new CSharpRewriteVisitor(virtualEvents).Visit(syntax));
        }
Example #2
0
        private static void VisitEvents(Thing thing, IEnumerable <IInterceptorFactory> factories)
        {
            var intercepts = factories
                             .Select(x => x.CreatEventIntercept())
                             .ToArray();

            EventVisitor.Visit(intercepts, thing);
        }
Example #3
0
 /// <summary>
 /// Accept a visit by the given visitor.
 /// </summary>
 public override TResult Accept <TResult, TData>(EventVisitor <TResult, TData> visitor, TData data)
 {
     return(visitor.Visit(this, data));
 }