Example #1
0
        public void Execute(GeneratorExecutionContext context)
        {
            var parseOptions = (CSharpParseOptions)context.ParseOptions;

            parseOptions = parseOptions.WithLanguageVersion(LanguageVersion.CSharp4);
            var compilation = (CSharpCompilation)context.Compilation;
            var rewriter    = new DummyRewriter();
            var list        = new List <SyntaxTree>(compilation.SyntaxTrees.Length);

            foreach (var tree in compilation.SyntaxTrees)
            {
                if (tree.FilePath.EndsWith("Resources.Designer.cs"))
                {
                    continue;
                }
                var newRoot = rewriter.Visit(tree.GetRoot(context.CancellationToken));
                list.Add(tree.WithRootAndOptions(newRoot, parseOptions));
            }
            compilation = compilation.RemoveAllSyntaxTrees().AddSyntaxTrees(list);

            var resolver = new EmbeddingResolver(
                compilation,
                parseOptions,
                new DummyDiagnosticReporter(),
                new EmbedderConfig(
                    true,
                    EmbeddingType.GZipBase32768,
                    excludeAttributes: new[] {
                "System.Runtime.CompilerServices.MethodImplAttribute",
                "System.Runtime.CompilerServices.CallerFilePathAttribute"
            },
                    minifyLevel: MinifyLevel.Full),
                context.CancellationToken);

            context.AddSource(
                "EmbeddedSourceCode.Metadata.Generated.cs", CreateMetadataSource(resolver.EnumerateAssemblyMetadata()));
        }
 public void ResolveCommomPrefixTest(IEnumerable <string> strs, string expected)
 => EmbeddingResolver.ResolveCommomPrefix(strs).Should().Be(expected);