Esempio n. 1
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}");
        }