コード例 #1
0
        public static void Add()
        {
            var aggregator1      = new StyleAggregator();
            var compilationUnit1 = SyntaxFactory.ParseCompilationUnit(
                @"public static class Test
{
	public static void VarFoo()
	{
		var a = 1;
	}
}", options: Shared.ParseOptions);

            aggregator1 = aggregator1.Add(compilationUnit1, StyleAggregatorTests.CreateModel(compilationUnit1.SyntaxTree));

            var aggregator2      = new StyleAggregator();
            var compilationUnit2 = SyntaxFactory.ParseCompilationUnit(
                @"public static class Test
{
	public static void TypeFoo()
	{
		int a = 1;
	}
}", options: Shared.ParseOptions);

            aggregator2 = aggregator2.Add(compilationUnit2, StyleAggregatorTests.CreateModel(compilationUnit2.SyntaxTree));

            var aggregator3 = aggregator1.Update(aggregator2);
            var data3       = aggregator3.Set.CSharpStyleVarForBuiltInTypesStyle.Data;

            Assert.That(data3.TotalOccurences, Is.EqualTo(2u), nameof(data3.TotalOccurences));
            Assert.That(data3.TrueOccurences, Is.EqualTo(1u), nameof(data3.TrueOccurences));
            Assert.That(data3.FalseOccurences, Is.EqualTo(1u), nameof(data3.FalseOccurences));
        }
コード例 #2
0
    public static async Task <string> Generate(DirectoryInfo directory, TextWriter writer, bool generateStatistics = false)
    {
        if (directory is null)
        {
            throw new ArgumentNullException(nameof(directory));
        }

        if (writer is null)
        {
            throw new ArgumentNullException(nameof(writer));
        }

        var aggregator = new StyleAggregator();

        await writer.WriteLineAsync($"Analyzing {directory}...").ConfigureAwait(false);

        foreach (var file in directory.EnumerateFiles("*.cs", SearchOption.AllDirectories))
        {
            await writer.WriteLineAsync($"\tAnalyzing {file.FullName}...").ConfigureAwait(false);

            var(unit, model) = StyleGenerator.GetCompilationInformation(file.FullName);
            aggregator       = aggregator.Update(new StyleAggregator().Add(unit, model));
        }

        if (generateStatistics)
        {
            using var statisticsWriter = File.CreateText("statistics.json");
            new JsonSerializer().Serialize(statisticsWriter, aggregator);
        }

        return(aggregator.GenerateConfiguration());
    }