Example #1
0
        public override MetadataItem VisitEvent(IEventSymbol symbol)
        {
            var item = GetMetadataItem(symbol);

            if (item == null)
            {
                return(null);
            }

            item.EnsureSyntax();

            item.Syntax.Content = symbol.GenerateSyntax(item.Type, ApiFilter);
            item.Modifiers      = symbol.GetMemberModifiersAsStrings();

            item.Syntax.Return = CreateParameter(symbol, item, true);

            item.Implements = symbol.GetMemberImplements(ApiFilter);

            item.Attributes = GetAttributeInfo(symbol.GetAttributes());

            item.IsExplicitInterfaceImplementation =
                !symbol.ExplicitInterfaceImplementations.IsEmpty;

            return(item);
        }
Example #2
0
        public override MetadataItem VisitEvent(IEventSymbol symbol)
        {
            MetadataItem result = GetYamlItem(symbol);

            if (result == null)
            {
                return(null);
            }
            if (result.Syntax == null)
            {
                result.Syntax = new SyntaxDetail {
                    Content = new SortedList <SyntaxLanguage, string>()
                };
            }
            if (result.Syntax.Content == null)
            {
                result.Syntax.Content = new SortedList <SyntaxLanguage, string>();
            }
            _generator.GenerateSyntax(result.Type, symbol, result.Syntax, this);
            _generator.GenerateEvent(symbol, result, this);

            var typeGenericParameters = symbol.ContainingType.IsGenericType ? symbol.ContainingType.Accept(TypeGenericParameterNameVisitor.Instance) : EmptyListOfString;

            if (symbol.IsOverride && symbol.OverriddenEvent != null)
            {
                result.Overridden = AddSpecReference(symbol.OverriddenEvent, typeGenericParameters);
            }

            var id = AddSpecReference(symbol.Type, typeGenericParameters);

            result.Syntax.Return = VisitorHelper.GetParameterDescription(symbol, result, id, true, GetTripleSlashCommentParserContext(result, _preserveRawInlineComments));
            Debug.Assert(result.Syntax.Return.Type != null);

            AddMemberImplements(symbol, result, typeGenericParameters);

            result.Attributes = GetAttributeInfo(symbol.GetAttributes());

            result.IsExplicitInterfaceImplementation = !symbol.ExplicitInterfaceImplementations.IsEmpty;

            return(result);
        }
Example #3
0
        /// <summary>
        /// Prepares the <see cref="EventMemberBuilder"/> from the <paramref name="symbol"/>
        /// and adds it to <see cref="TypeMemberBuilder.ContentMembers"/>
        /// </summary>
        /// <param name="symbol">Source <see cref="INamedTypeSymbol"/></param>
        /// <param name="root">Builder root</param>
        /// <param name="type">Parent <see cref="TypeMemberBuilder"/></param>
        /// <param name="level">Hierarchy level (used to indent the console output)</param>
        private static void BuildEvent(IEventSymbol symbol, RootMemberBuilder root, TypeMemberBuilder type, int level)
        {
            if (symbol.IsImplicitlyDeclared)
            {
                return;
            }
            if (symbol.GetAttributes().Any(a => a.AttributeClassString() == "System.Runtime.CompilerServices.CompilerGeneratedAttribute"))
            {
                return;
            }

            var e = new EventMemberBuilder
            {
                Name                    = symbol.Name,
                NameBase                = symbol.Name,
                Symbol                  = symbol,
                SourceFiles             = symbol.DeclaringSyntaxReferences.Select(dsr => dsr.SyntaxTree.FilePath).ToList(),
                DocumentationId         = symbol.GetDocumentationCommentId(),
                DocumentationXml        = symbol.GetDocumentationCommentXml(),
                Documentation           = Documentation.Read(symbol.GetDocumentationCommentXml()),
                Modifier                = ModifierEnumExtensions.Modifier(symbol.DeclaredAccessibility),
                IsAbstract              = symbol.IsAbstract,
                IsExtern                = symbol.IsExtern,
                IsSealed                = symbol.IsSealed,
                IsStatic                = symbol.IsStatic,
                IsOverride              = symbol.IsOverride,
                IsVirtual               = symbol.IsVirtual,
                HasExplicitAddAndRemove = !symbol.AddMethod.IsImplicitlyDeclared && !symbol.RemoveMethod.IsImplicitlyDeclared,
                TypeRef                 = TypeRef.GetOrCreate(symbol.Type, root),
                IsNew                   = symbol.GetIsNew(),
                OverridesSymbol         = symbol.OverriddenEvent,
                ExplicitInterfaceImplementationMemberSymbol =
                    symbol.ExplicitInterfaceImplementations != null && symbol.ExplicitInterfaceImplementations.Length > 0
                        ? symbol.ExplicitInterfaceImplementations[0]
                        : null
            };

            e.SetAttributes(root);
            type.ContentMembers.Add(e);
            Console.WriteLine($"{new string(' ', level)} read as {e}");
        }
Example #4
0
 private static MemberDeclarationSyntax GenerateEventFieldDeclaration(
     IEventSymbol @event,
     CodeGenerationDestination destination,
     CodeGenerationOptions options
     )
 {
     return(AddFormatterAndCodeGeneratorAnnotationsTo(
                AddAnnotationsTo(
                    @event,
                    SyntaxFactory.EventFieldDeclaration(
                        AttributeGenerator.GenerateAttributeLists(@event.GetAttributes(), options),
                        GenerateModifiers(@event, destination, options),
                        SyntaxFactory.VariableDeclaration(
                            @event.Type.GenerateTypeSyntax(),
                            SyntaxFactory.SingletonSeparatedList(
                                SyntaxFactory.VariableDeclarator(@event.Name.ToIdentifierToken())
                                )
                            )
                        )
                    )
                ));
 }
Example #5
0
        private static MemberDeclarationSyntax GenerateEventDeclarationWorker(
            IEventSymbol @event,
            CodeGenerationDestination destination,
            CodeGenerationOptions options
            )
        {
            var explicitInterfaceSpecifier = GenerateExplicitInterfaceSpecifier(
                @event.ExplicitInterfaceImplementations
                );

            return(AddFormatterAndCodeGeneratorAnnotationsTo(
                       SyntaxFactory.EventDeclaration(
                           attributeLists: AttributeGenerator.GenerateAttributeLists(
                               @event.GetAttributes(),
                               options
                               ),
                           modifiers: GenerateModifiers(@event, destination, options),
                           type: @event.Type.GenerateTypeSyntax(),
                           explicitInterfaceSpecifier: explicitInterfaceSpecifier,
                           identifier: @event.Name.ToIdentifierToken(),
                           accessorList: GenerateAccessorList(@event, destination, options)
                           )
                       ));
        }
Example #6
0
        private static MemberDeclarationSyntax GenerateEventDeclarationWorker(
            IEventSymbol @event, CodeGenerationDestination destination, CodeGenerationOptions options)
        {
            var explicitInterfaceSpecifier = GenerateExplicitInterfaceSpecifier(@event.ExplicitInterfaceImplementations);

            return AddCleanupAnnotationsTo(SyntaxFactory.EventDeclaration(
                attributeLists: AttributeGenerator.GenerateAttributeLists(@event.GetAttributes(), options),
                modifiers: GenerateModifiers(@event, destination, options),
                type: @event.Type.GenerateTypeSyntax(),
                explicitInterfaceSpecifier: explicitInterfaceSpecifier,
                identifier: @event.Name.ToIdentifierToken(),
                accessorList: GenerateAccessorList(@event, destination, options)));
        }
Example #7
0
 private static MemberDeclarationSyntax GenerateEventFieldDeclaration(
     IEventSymbol @event, CodeGenerationDestination destination, CodeGenerationOptions options)
 {
     return AddCleanupAnnotationsTo(
         AddAnnotationsTo(@event,
             SyntaxFactory.EventFieldDeclaration(
                 AttributeGenerator.GenerateAttributeLists(@event.GetAttributes(), options),
                 GenerateModifiers(@event, destination, options),
                 SyntaxFactory.VariableDeclaration(
                     @event.Type.GenerateTypeSyntax(),
                     SyntaxFactory.SingletonSeparatedList(SyntaxFactory.VariableDeclarator(@event.Name.ToIdentifierToken()))))));
 }