예제 #1
0
        public void GlobalSetup()
        {
            var roslynRoot = Environment.GetEnvironmentVariable(
                Program.RoslynRootPathEnvVariableName
                );
            var csFilePath = Path.Combine(
                roslynRoot,
                @"src\Compilers\CSharp\Portable\Generated\Syntax.xml.Syntax.Generated.cs"
                );

            if (!File.Exists(csFilePath))
            {
                throw new ArgumentException();
            }

            // Remove some newlines
            var text = File.ReadAllText(csFilePath)
                       .Replace("<auto-generated />", "")
                       .Replace($"{{{Environment.NewLine}{Environment.NewLine}", "{")
                       .Replace($"}}{Environment.NewLine}{Environment.NewLine}", "}")
                       .Replace($"{{{Environment.NewLine}", "{")
                       .Replace($"}}{Environment.NewLine}", "}")
                       .Replace($";{Environment.NewLine}", ";");

            var projectId  = ProjectId.CreateNewId();
            var documentId = DocumentId.CreateNewId(projectId);

            var solution = new AdhocWorkspace().CurrentSolution
                           .AddProject(projectId, "ProjectName", "AssemblyName", LanguageNames.CSharp)
                           .AddDocument(documentId, "DocumentName", text);

            var document = solution.GetDocument(documentId);
            var root     = document
                           .GetSyntaxRootAsync(CancellationToken.None)
                           .Result.WithAdditionalAnnotations(Formatter.Annotation);

            solution = solution.WithDocumentSyntaxRoot(documentId, root);

            _document = solution.GetDocument(documentId);
            _options  = _document
                        .GetOptionsAsync()
                        .Result.WithChangedOption(CSharpFormattingOptions.NewLinesForBracesInTypes, true)
                        .WithChangedOption(
                CSharpFormattingOptions.WrappingKeepStatementsOnSingleLine,
                false
                )
                        .WithChangedOption(CSharpFormattingOptions.WrappingPreserveSingleLine, false);
        }
예제 #2
0
        public void GlobalSetup()
        {
            var roslynRoot = Environment.GetEnvironmentVariable(Program.RoslynRootPathEnvVariableName);
            var csFilePath = Path.Combine(roslynRoot, @"src\Compilers\CSharp\Portable\Generated\Syntax.xml.Syntax.Generated.cs");

            if (!File.Exists(csFilePath))
            {
                throw new ArgumentException();
            }

            // Remove some newlines
            var text = File.ReadAllText(csFilePath).Replace("<auto-generated />", "")
                       .Replace($"{{{Environment.NewLine}{Environment.NewLine}", "{")
                       .Replace($"}}{Environment.NewLine}{Environment.NewLine}", "}")
                       .Replace($"{{{Environment.NewLine}", "{")
                       .Replace($"}}{Environment.NewLine}", "}")
                       .Replace($";{Environment.NewLine}", ";");

            var projectId  = ProjectId.CreateNewId();
            var documentId = DocumentId.CreateNewId(projectId);

            var solution = new AdhocWorkspace().CurrentSolution
                           .AddProject(projectId, "ProjectName", "AssemblyName", LanguageNames.CSharp)
                           .AddDocument(documentId, "DocumentName", text);

            var document = solution.GetDocument(documentId);
            var root     = document.GetSyntaxRootAsync(CancellationToken.None).Result.WithAdditionalAnnotations(Formatter.Annotation);

            solution = solution.WithDocumentSyntaxRoot(documentId, root);

            _document = solution.GetDocument(documentId);
            _options  = new CSharpSyntaxFormattingOptions(
                LineFormattingOptions.Default,
                separateImportDirectiveGroups: CSharpSyntaxFormattingOptions.Default.SeparateImportDirectiveGroups,
                spacing: CSharpSyntaxFormattingOptions.Default.Spacing,
                spacingAroundBinaryOperator: CSharpSyntaxFormattingOptions.Default.SpacingAroundBinaryOperator,
                CSharpSyntaxFormattingOptions.Default.NewLines | NewLinePlacement.BeforeOpenBraceInTypes,
                labelPositioning: CSharpSyntaxFormattingOptions.Default.LabelPositioning,
                indentation: CSharpSyntaxFormattingOptions.Default.Indentation,
                wrappingKeepStatementsOnSingleLine: false,
                wrappingPreserveSingleLine: false);
        }