public void Execute(GeneratorExecutionContext context) { var syntaxReceiver = (StructSyntaxReceiver)(context.SyntaxReceiver ?? throw new InvalidOperationException("Missing syntax receiver!")); if (syntaxReceiver is null) { return; } bool isNullableEnabled = context.Compilation.Options.NullableContextOptions != NullableContextOptions.Disable; var result = new StringBuilder(512); foreach (var s in syntaxReceiver.Nodes) { var tree = s.Identifier.SyntaxTree; if (tree is null) { continue; } var semanticModel = context.Compilation.GetSemanticModel(tree); var symbol = semanticModel.GetDeclaredSymbol(s.Struct); string?typeName = CodeBuilder.MakeTypeName(s.ValueType, semanticModel); var typeSymbol = semanticModel.GetTypeInfo(s.ValueType).Type; bool isReferenceType; if (typeSymbol is not null) { isReferenceType = typeSymbol.IsReferenceType; } else { isReferenceType = false; } if (typeName is null || symbol is null) { continue; } result.Clear(); result.AddPreamble(symbol, s); result.AddConstructor(typeName, s); result.AddEquals(typeName, isNullableEnabled, isReferenceType, s); if (!s.HasToString) { result.AddToString(typeName, s); } if (s.Comparable == IsComparable.Comparable) { result.AddComparison(s); } result.AddEndOfFile(); var filename = @$ "id-{s.Identifier}.cs"; context.AddSource(filename, SourceText.From(result.ToString(), Encoding.UTF8)); } }