public static string Build(GeneratorExecutionContext generatorExecutionContext,
                            CompilationDiagnosticsManager compilationDiagnosticsManager, INamedTypeSymbol classSymbol,
                            Dictionary <SyntaxNode, AttributeSyntax[]> receiverCandidateMembers,
                            Dictionary <AttributeSyntax, SyntaxNode> receiverCandidateAttributes)
 {
     return(new IoTHubPartialClassBuilder(generatorExecutionContext, compilationDiagnosticsManager, classSymbol, receiverCandidateMembers,
                                          receiverCandidateAttributes).Result);
 }
Exemplo n.º 2
0
        private static void AddIoTHubGeneratedClass(GeneratorExecutionContext context,
                                                    CompilationDiagnosticsManager compilationDiagnosticsManager, ISymbol iotHubSymbol,
                                                    Dictionary <SyntaxNode, AttributeSyntax[]> receiverCandidateMembers,
                                                    Dictionary <AttributeSyntax, SyntaxNode> receiverCandidateAttributes)
        {
            AddSource($"{iotHubSymbol.Name}Extension.IoTHub.g.cs",
                      IoTHubPartialClassBuilder.Build(context, compilationDiagnosticsManager, iotHubSymbol as INamedTypeSymbol, receiverCandidateMembers, receiverCandidateAttributes));

            void AddSource(string sourceFileName, string sourceCode)
            {
                var sourceText = CSharpSyntaxTree
                                 .ParseText(SourceText.From(sourceCode, Encoding.UTF8))
                                 .GetRoot().NormalizeWhitespace()
                                 .GetText(Encoding.UTF8);

                context.AddSource(sourceFileName, sourceText);
            }
        }
        public IoTHubPartialClassBuilder(GeneratorExecutionContext generatorExecutionContext,
                                         CompilationDiagnosticsManager diagnosticsManager,
                                         INamedTypeSymbol classSymbol,
                                         Dictionary <SyntaxNode, AttributeSyntax[]> receiverCandidateMembers,
                                         Dictionary <AttributeSyntax, SyntaxNode> receiverCandidateAttributes)
        {
            _generatorExecutionContext   = generatorExecutionContext;
            _diagnosticsManager          = diagnosticsManager;
            _receiverCandidateMembers    = receiverCandidateMembers;
            _receiverCandidateAttributes = receiverCandidateAttributes;
            Class = classSymbol;
            var @namespace = Class.ContainingNamespace.ToDisplayString();

            try
            {
                BuildPartialClass(@namespace, Class.Name);
            }
            catch (Exception e)
            {
                AppendLine($"#error in IoTHub Client generator, error {e}");
            }
        }