示例#1
0
        private static SyntaxTokenList GenerateModifiers(
            IEventSymbol @event, CodeGenerationDestination destination, CSharpCodeGenerationOptions options)
        {
            var tokens = ArrayBuilder <SyntaxToken> .GetInstance();

            // Most modifiers not allowed if we're an explicit impl.
            if ([email protected]())
            {
                if (destination != CodeGenerationDestination.InterfaceType)
                {
                    AddAccessibilityModifiers(@event.DeclaredAccessibility, tokens, options, Accessibility.Private);

                    if (@event.IsStatic)
                    {
                        tokens.Add(SyntaxFactory.Token(SyntaxKind.StaticKeyword));
                    }

                    // An event is readonly if its accessors are readonly.
                    // If one accessor is readonly and the other one is not,
                    // the event is malformed and cannot be properly displayed.
                    // See https://github.com/dotnet/roslyn/issues/34213
                    // Don't show the readonly modifier if the containing type is already readonly
                    if (@event.AddMethod?.IsReadOnly == true && [email protected])
                    {
                        tokens.Add(SyntaxFactory.Token(SyntaxKind.ReadOnlyKeyword));
                    }

                    if (@event.IsAbstract)
                    {
                        tokens.Add(SyntaxFactory.Token(SyntaxKind.AbstractKeyword));
                    }

                    if (@event.IsOverride)
                    {
                        tokens.Add(SyntaxFactory.Token(SyntaxKind.OverrideKeyword));
                    }
                }
            }

            if (CodeGenerationEventInfo.GetIsUnsafe(@event))
            {
                tokens.Add(SyntaxFactory.Token(SyntaxKind.UnsafeKeyword));
            }

            return(tokens.ToSyntaxTokenListAndFree());
        }
示例#2
0
        private static SyntaxTokenList GenerateModifiers(
            IEventSymbol @event, CodeGenerationDestination destination, CodeGenerationOptions options)
        {
            var tokens = new List <SyntaxToken>();

            // Most modifiers not allowed if we're an explicit impl.
            if ([email protected]())
            {
                if (destination != CodeGenerationDestination.InterfaceType)
                {
                    AddAccessibilityModifiers(@event.DeclaredAccessibility, tokens, options, Accessibility.Private);

                    if (@event.IsStatic)
                    {
                        tokens.Add(SyntaxFactory.Token(SyntaxKind.StaticKeyword));
                    }

                    if (@event.IsAbstract)
                    {
                        tokens.Add(SyntaxFactory.Token(SyntaxKind.AbstractKeyword));
                    }

                    if (@event.IsOverride)
                    {
                        tokens.Add(SyntaxFactory.Token(SyntaxKind.OverrideKeyword));
                    }
                }
            }

            if (CodeGenerationEventInfo.GetIsUnsafe(@event))
            {
                tokens.Add(SyntaxFactory.Token(SyntaxKind.UnsafeKeyword));
            }

            return(tokens.ToSyntaxTokenList());
        }