public void Execute(GeneratorExecutionContext context) { // Add the attribute declaration context.AddSource("constructFromAttr", ConstructFromGenerator.constructFromAttrSource); // Get the syntax receiver if (context.SyntaxReceiver is not ConstructFromSyntaxReceiver syntaxReceiver) { context.ReportInternalError("Unexpected error: could not retrieve the syntax."); return; } // Add the conversions var messages = new List <string>(syntaxReceiver.Messages); foreach (var candidate in syntaxReceiver.Candidates) { messages.Add( $"Candidate type found: {candidate.TypeDeclaration.Identifier.ValueText} from {candidate.FromType}" ); // Get the semantic model of the type declaration var semanticModel = context.Compilation.GetSemanticModel(candidate.TypeDeclaration.SyntaxTree); var typeDeclarationSymbol = semanticModel.GetDeclaredSymbol( candidate.TypeDeclaration, context.CancellationToken ); if (typeDeclarationSymbol is null) { context.ReportInternalError( "Unexpected error: could not get type information for fromType.", location: candidate.FromType.GetLocation() ); continue; } // TODO: reject generic types - not yet implemented if (typeDeclarationSymbol.IsGenericType) { context.ReportInternalError( "Generic types are currently not supported.", location: candidate.FromType.GetLocation() ); continue; } // Get the target type's symbol var fromTypeSymbolInfo = semanticModel.GetSymbolInfo( candidate.FromType, context.CancellationToken ); if (fromTypeSymbolInfo.Symbol is not INamedTypeSymbol fromTypeSymbol) { context.ReportInternalError( "Unexpected error: could not get type information for fromType.", location: candidate.FromType.GetLocation() ); continue; } // Reject unbound generic types if (fromTypeSymbol.IsUnboundGenericType) { context.ReportError( Constants.UnboundGenericErrorId, "Unbound generic types are not supported.", location: candidate.FromType.GetLocation() ); continue; } // Type kind name var typeKindName = typeDeclarationSymbol switch { { IsRecord : true } => "record",