Exemplo n.º 1
0
 public static void ReportDiagnosticIfNonGenerated(
     this SymbolAnalysisContext context,
     GeneratedCodeRecognizer generatedCodeRecognizer,
     Diagnostic diagnostic)
 {
     context.ReportDiagnosticIfNonGenerated(generatedCodeRecognizer, diagnostic, context.Compilation);
 }
Exemplo n.º 2
0
 public static void ReportDiagnosticIfNonGenerated(
     this CompilationAnalysisContext context,
     GeneratedCodeRecognizer generatedCodeRecognizer,
     Diagnostic diagnostic,
     Compilation compilation)
 {
     if (!diagnostic.Location.SourceTree.IsGenerated(generatedCodeRecognizer, compilation))
     {
         context.ReportDiagnostic(diagnostic);
     }
 }
Exemplo n.º 3
0
 public static void RegisterCodeBlockStartActionInNonGenerated <TLanguageKindEnum>(
     this AnalysisContext context,
     GeneratedCodeRecognizer generatedCodeRecognizer,
     Action <CodeBlockStartAnalysisContext <TLanguageKindEnum> > action) where TLanguageKindEnum : struct
 {
     context.RegisterCodeBlockStartAction <TLanguageKindEnum>(
         c =>
     {
         if (!c.CodeBlock.SyntaxTree.IsGenerated(generatedCodeRecognizer, c.SemanticModel.Compilation))
         {
             action(c);
         }
     });
 }
        private static async Task<bool> IsGeneratedAsync(string content, GeneratedCodeRecognizer generatedCodeRecognizer)
        {
            using (var workspace = new AdhocWorkspace())
            {
                var document = workspace.CurrentSolution.AddProject("foo", "foo.dll", LanguageNames.CSharp)
                    .AddMetadataReference(MetadataReference.CreateFromFile(typeof(object).Assembly.Location))
                    .AddMetadataReference(MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location))
                    .AddDocument("Foo.cs", content);

                var compilation = document.Project.GetCompilationAsync().Result;
                var tree = await document.GetSyntaxTreeAsync();

                return tree.IsGenerated(generatedCodeRecognizer, compilation);
            }
        }
Exemplo n.º 5
0
 public static void RegisterSyntaxNodeActionInNonGenerated <TLanguageKindEnum>(
     this AnalysisContext context,
     GeneratedCodeRecognizer generatedCodeRecognizer,
     Action <SyntaxNodeAnalysisContext> action,
     params TLanguageKindEnum[] syntaxKinds) where TLanguageKindEnum : struct
 {
     context.RegisterSyntaxNodeAction(
         c =>
     {
         if (!c.Node.SyntaxTree.IsGenerated(generatedCodeRecognizer, c.SemanticModel.Compilation))
         {
             action(c);
         }
     },
         syntaxKinds);
 }
Exemplo n.º 6
0
 public static void RegisterSyntaxTreeActionInNonGenerated(
     this AnalysisContext context,
     GeneratedCodeRecognizer generatedCodeRecognizer,
     Action <SyntaxTreeAnalysisContext> action)
 {
     context.RegisterCompilationStartAction(
         csac =>
     {
         csac.RegisterSyntaxTreeAction(
             c =>
         {
             if (!c.Tree.IsGenerated(generatedCodeRecognizer, csac.Compilation))
             {
                 action(c);
             }
         });
     });
 }
Exemplo n.º 7
0
        private static bool IsGenerated(this SyntaxTree tree,
                                        GeneratedCodeRecognizer generatedCodeRecognizer,
                                        Compilation compilation)
        {
            if (tree == null)
            {
                return(false);
            }

            //this is locking if the compilation is not present in the Cache.
            var  cache = Cache.GetOrCreateValue(compilation);
            bool result;

            if (cache.TryGetValue(tree, out result))
            {
                return(result);
            }

            var generated = generatedCodeRecognizer.IsGenerated(tree);

            cache.TryAdd(tree, generated);
            return(generated);
        }