Example #1
0
        public override string?VisitEvent(IEventSymbol symbol)
        {
            if (symbol.IsCanBeOverriden() == false)
            {
                return(null);
            }

            var result = new StringBuilder("override ")
                         .AppendParts(symbol
                                      .ToDisplayParts(SymbolDisplayFormats.AbstractClass)
                                      .FilterInternalKeywordFromNonFriendDeclarations(symbol, compilation))
                         .AppendEventAddRemove(VariableNames.PropertiesContext, symbol, methodName: "Invoke");

            if (symbol.IsInterfaceRequired())
            {
                AddInterfaceImplementation(symbol, result);
            }
            return(result.ToString());
        }
Example #2
0
        protected string?VisitEvent(IEventSymbol symbol, Func <StringBuilder, IEventSymbol, StringBuilder> appendEventAddRemove)
        {
            var ct     = symbol.ContainingType;
            var result = new StringBuilder();

            if (ct.Name != nameof(Object) && ct.BaseType == null)
            {
                result.Append(symbol, SymbolDisplayFormats.Interface);
                appendEventAddRemove(result, symbol);
                return(result.ToString());
            }
            if (symbol.IsCanBeOverriden())
            {
                result.Append("override ")
                .AppendParts(symbol
                             .ToDisplayParts(SymbolDisplayFormats.AbstractClass)
                             .FilterInternalKeywordFromNonFriendDeclarations(symbol, compilation));
                appendEventAddRemove(result, symbol);

                if (implementationName != null && symbol.IsInterfaceRequired())
                {
                    result.Append(symbol, SymbolDisplayFormats.Interface, Mutator);
                    appendEventAddRemove(result, symbol);

                    SymbolDisplayPart Mutator(SymbolDisplayPart part)
                    {
                        if (part.Kind == SymbolDisplayPartKind.ClassName && implementationName == part.ToString())
                        {
                            return(new SymbolDisplayPart(part.Kind, part.Symbol, Prefix.ProtectedToPublicInterface + implementationName));
                        }
                        return(part);
                    }
                }
                return(result.ToString());
            }
            return(null);
        }