public static void Analyze(SyntaxNodeAnalysisContext context, RegionDirectiveTriviaSyntax region)
        {
            if (region.IsKind(SyntaxKind.RegionDirectiveTrivia))
            {
                List <DirectiveTriviaSyntax> relatedDirectives = region.GetRelatedDirectives();

                if (relatedDirectives.Count == 2 &&
                    relatedDirectives[1].IsKind(SyntaxKind.EndRegionDirectiveTrivia))
                {
                    DirectiveTriviaSyntax endRegion = relatedDirectives[1];

                    if (endRegion.IsKind(SyntaxKind.EndRegionDirectiveTrivia))
                    {
                        SyntaxTrivia trivia = region.ParentTrivia;

                        SyntaxTriviaList list = trivia.GetContainingList();

                        if (list.Any())
                        {
                            EndRegionDirectiveTriviaSyntax endRegion2 = FindEndRegion(list, list.IndexOf(trivia));

                            if (endRegion == endRegion2)
                            {
                                context.ReportDiagnostic(
                                    DiagnosticDescriptors.RemoveEmptyRegion,
                                    region.GetLocation(),
                                    endRegion.GetLocation());
                            }
                        }
                    }
                }
            }
        }
        private static void HandleRegionDirectiveTrivia(SyntaxNodeAnalysisContext context)
        {
            RegionDirectiveTriviaSyntax regionSyntax = (RegionDirectiveTriviaSyntax)context.Node;

            if (IsCompletelyContainedInBody(regionSyntax))
            {
                // Region must not be located within a code element.
                context.ReportDiagnostic(Diagnostic.Create(Descriptor, regionSyntax.GetLocation()));
            }
        }
        private void HandleRegionDirectiveTrivia(SyntaxNodeAnalysisContext context)
        {
            RegionDirectiveTriviaSyntax regionSyntax = context.Node as RegionDirectiveTriviaSyntax;

            // regions that are completely inside a body are handled by SA1123.
            if (regionSyntax != null && !SA1123DoNotPlaceRegionsWithinElements.IsCompletelyContainedInBody(regionSyntax))
            {
                // Regions must not be used.
                context.ReportDiagnostic(Diagnostic.Create(Descriptor, regionSyntax.GetLocation()));
            }
        }