diff --git a/Decomposer/src/DecomposerConstants.cs b/Decomposer/src/DecomposerConstants.cs index 6c46a93..c44d47b 100644 --- a/Decomposer/src/DecomposerConstants.cs +++ b/Decomposer/src/DecomposerConstants.cs @@ -52,65 +52,87 @@ public static class Constants DecomposedInterfaceHeader + GeneratedCodeAttribue + $$$""" - public interface I{{ decomposed_from }}{{ memeber_name }} - { - """; + public interface I {{ decomposed_from } + }{{ memeber_name +}} + { + """; public static readonly Scriban.Template IDecomposedMarkerInterfaceDeclarationTemplate = - Scriban.Template.Parse(IDecomposedMarkerInterfaceDeclaration); - - public const string DecomposedPropertyDeclaration = - GeneratedCodeAttribue - + """ - {{ property_type }} {{ property_name }} { {{ if is_gettable }} get; {{ end }} {{ if is_settable }} set; {{ end }} } - """; + Scriban.Template.Parse(IDecomposedMarkerInterfaceDeclaration); + +public const string DecomposedPropertyDeclaration = + GeneratedCodeAttribue + + """ + { { property_type } } +{ { property_name } } +{ { { if is_gettable } } get; { { end } } { { if is_settable } } set; { { end } } } +"""; public static readonly Scriban.Template DecomposedPropertyDeclarationTemplate = - Scriban.Template.Parse(DecomposedPropertyDeclaration); - - public const string DecomposedMethodDeclaration = - GeneratedCodeAttribue - + """ - {{ return_type }} {{ method_name }} ({{ for parameter in parameters }}{{ parameter.type }} {{ parameter.name }}{{ if not loop.last }}, {{ endif }}{{ endfor }}) - {{ if has_generic_type_constraints }} - {{ for generic_type_constraint in generic_type_constraints }} where {{ generic_type_constraint.name }} : {{ type_constraint.constraint }} - {{ endfor }} - {{ endif }} - """; - - public const string DecomposableAttributeFilename = "DecomposableAttribute.g.cs"; - - public const string DecomposableAttributeDeclaration = - DecomposedInterfaceHeader - + """ - [global::System.AttributeUsage(global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Assembly)] - public sealed class DecomposeAttribute : global::System.Attribute - { - public DecomposeAttribute() { } - public DecomposeAttribute(global::System.Type type) { } - } - """; + Scriban.Template.Parse(DecomposedPropertyDeclaration); + +public const string DecomposedMethodDeclaration = + GeneratedCodeAttribue + + """ + { { return_type } } +{ { method_name } } ({ { for parameter in parameters } } +{ { parameter.type } } +{ { parameter.name } } +{ { if not loop.last } }, { { endif } } +{ { endfor } }) + { { if has_generic_type_constraints } } +{ { for generic_type_constraint in generic_type_constraints } } +where +{ { generic_type_constraint.name } } : { { type_constraint.constraint } } +{ { endfor } } +{ { endif } } +"""; + + public const string DecomposableAttributeFilename = "DecomposableAttribute.g.cs"; + +public const string DecomposableAttributeDeclaration = + DecomposedInterfaceHeader + + """ +[global::System.AttributeUsage(global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Assembly)] + public sealed class DecomposeAttribute : global::System.Attribute +{ + public DecomposeAttribute() { } + public DecomposeAttribute(global::System.Type type) { } +} +"""; public static readonly Scriban.Template DecomposedMethodDeclarationTemplate = - Scriban.Template.Parse(DecomposedMethodDeclaration); - - public const string IComposedClassDeclaration = """ - public partial class {{ class_name }} : {{ for type_member_tuple in decomposed_from }} IDecomposed<{{} decomposed_from.type }}> - { - {{ for type_member_tuple in decomposed_from }} - {{ if type_member_tuple.member.is_property }} - public {{ type_member_tuple.member.type }} {{ type_member_tuple.member.name }} {{ get; }} - {{ elif type_member_tuple.member.is_method }} - public {{ decomposed_from.type }} {{} decomposed_from.member }} {{ get; }} - {{ endfor }} - - - public { class_name }({ decomposed_from } decomposed) - { - { decomposed_from } = decomposed; - } - - public { decomposed_from } { decomposed_from } {{ get; }} + Scriban.Template.Parse(DecomposedMethodDeclaration); + +public const string IComposedClassDeclaration = """ + public partial class {{ class_name }} : { { for type_member_tuple in decomposed_from } } +IDecomposed <{ { } decomposed_from.type }}> + { + { { for type_member_tuple in decomposed_from } } + { { if type_member_tuple.member.is_property } } + public +{ { type_member_tuple.member.type } } +{ { type_member_tuple.member.name } } +{ { get; } } +{ { elif type_member_tuple.member.is_method } } +public +{ { decomposed_from.type } } +{ { } decomposed_from.member }} { { get; } } +{ { endfor } } + + +public +{ class_name } ({ decomposed_from } +decomposed) + { + { decomposed_from } = decomposed; +} + +public +{ decomposed_from } +{ decomposed_from } +{ { get; } } } """; diff --git a/Decomposer/src/Resources/IDecomposable.cs b/Decomposer/src/Resources/IDecomposable.cs index ceba643..527d71c 100644 --- a/Decomposer/src/Resources/IDecomposable.cs +++ b/Decomposer/src/Resources/IDecomposable.cs @@ -11,8 +11,8 @@ */ public interface IDecomposed -{ - +{ + } diff --git a/Decomposer/src/chatwithopenaitogeneratethissolution/C#/convo1.cs b/Decomposer/src/chatwithopenaitogeneratethissolution/C#/convo1.cs index 2172ba6..ae43477 100644 --- a/Decomposer/src/chatwithopenaitogeneratethissolution/C#/convo1.cs +++ b/Decomposer/src/chatwithopenaitogeneratethissolution/C#/convo1.cs @@ -7,26 +7,27 @@ using Azure.AI.OpenAI; OpenAIClient client = new OpenAIClient( - new Uri("https://dgmjr-io.openai.azure.com/"), - new AzureKeyCredential(Environment.GetEnvironmentVariable("AZURE_OPENAI_API_KEY"))); + new Uri("https://dgmjr-io.openai.azure.com/"), + new AzureKeyCredential(Environment.GetEnvironmentVariable("AZURE_OPENAI_API_KEY"))); // ### If streaming is selected Response response = await client.GetChatCompletionsStreamingAsync( - deploymentOrModelName: "MyFirstOpenAI", - new ChatCompletionsOptions() - { - Messages = - { - new ChatMessage(ChatRole.System, @"Yo are an expert software architect, fluent in C#, TypeScript, Python, PowerShell, and MSIL. You are knowledgeable on the latest software design and security concepts and an expert at designing ""clean code."" Your job is to assist people with coding problems they have."), - new ChatMessage(ChatRole.User, @"Where/how is IncrementalGeneratorExecutionContext defined?"), - new ChatMessage(ChatRole.Assistant, @"The `IncrementalGeneratorExecutionContext` is part of the `Microsoft.CodeAnalysis` namespace, which is included in the `Microsoft.CodeAnalysis.Analyzers` NuGet package. You can install this package via the NuGet Package Manager or by adding the following line to your project file: + deploymentOrModelName: "MyFirstOpenAI", + new ChatCompletionsOptions() + { + Messages = + { + new ChatMessage(ChatRole.System, @"Yo are an expert software architect, fluent in C#, TypeScript, Python, PowerShell, and MSIL. You are knowledgeable on the latest software design and security concepts and an expert at designing ""clean code."" Your job is to assist people with coding problems they have."), + new ChatMessage(ChatRole.User, @"Where/how is IncrementalGeneratorExecutionContext defined?"), + new ChatMessage(ChatRole.Assistant, @"The `IncrementalGeneratorExecutionContext` is part of the `Microsoft.CodeAnalysis` namespace, which is included in the `Microsoft.CodeAnalysis.Analyzers` NuGet package. You can install this package via the NuGet Package Manager or by adding the following line to your project file: ```xml ``` Once you have the package installed, you can reference the `Microsoft.CodeAnalysis` namespace and access the `IncrementalGeneratorExecutionContext` class in your code."), - new ChatMessage(ChatRole.User, @"No it isn't."), + + new ChatMessage(ChatRole.User, @"No it isn't."), new ChatMessage(ChatRole.Assistant, @"I apologize for the confusion. The `IncrementalGeneratorExecutionContext` class is actually part of the `Microsoft.CodeAnalysis` namespace, but it is not currently available in the public API surface of the .NET Compiler Platform (Roslyn). The class was introduced in preview versions of Roslyn, but it was removed before the final release. If you want to use the `IncrementalGeneratorExecutionContext` class, you'll need to use a preview version of Roslyn, which may not be suitable for production use. Alternatively, you can use the `GeneratorExecutionContext` class, which is part of the public API surface and provides similar functionality to the `IncrementalGeneratorExecutionContext`. @@ -62,75 +63,75 @@ public class MyGenerator : ISourceGenerator private const string DecomposerGeneratorVersion = \"1.0.0\"; public void Initialize(GeneratorInitializationContext context) +{ + // No initialization needed +} + +public void Execute(GeneratorExecutionContext context) +{ + var typesToDecompose = new List(); + var assembliesToDecompose = new List(); + + // Find all types and assemblies marked with the Decompose attribute + foreach (var reference in context.Compilation.References) { - // No initialization needed + var symbol = context.Compilation.GetAssemblyOrModuleSymbol(reference); + if (symbol != null && symbol.GetAttributes().Any(attr => attr.AttributeClass?.Name == nameof(DecomposeAttribute))) + { + switch (symbol) + { + case IAssemblySymbol assembly: + assembliesToDecompose.Add(assembly); + break; + case INamedTypeSymbol type: + if (type.Constructors.Any(c => c.Parameters.Length == 0)) + { + typesToDecompose.Add(type); + } + break; + } + } } - public void Execute(GeneratorExecutionContext context) + foreach (var syntaxTree in context.Compilation.SyntaxTrees) { - var typesToDecompose = new List(); - var assembliesToDecompose = new List(); - - // Find all types and assemblies marked with the Decompose attribute - foreach (var reference in context.Compilation.References) + var semanticModel = context.Compilation.GetSemanticModel(syntaxTree); + foreach (var node in syntaxTree.GetRoot().DescendantNodes()) { - var symbol = context.Compilation.GetAssemblyOrModuleSymbol(reference); + var symbol = semanticModel.GetDeclaredSymbol(node); if (symbol != null && symbol.GetAttributes().Any(attr => attr.AttributeClass?.Name == nameof(DecomposeAttribute))) { switch (symbol) { - case IAssemblySymbol assembly: - assembliesToDecompose.Add(assembly); + case IAssemblySymbol assemblySymbol: + if (assemblySymbol.Constructors.Any(c => c.Parameters.Length == 2 && + c.Parameters[0].Type?.SpecialType == SpecialType.System_Type && + c.Parameters[1].Type?.SpecialType == SpecialType.System_String)) + { + assembliesToDecompose.Add(assemblySymbol); + } break; - case INamedTypeSymbol type: - if (type.Constructors.Any(c => c.Parameters.Length == 0)) + case INamedTypeSymbol namedTypeSymbol: + if (namedTypeSymbol.Constructors.Any(c => c.Parameters.Length == 0)) { - typesToDecompose.Add(type); + typesToDecompose.Add(namedTypeSymbol); } break; } } } + } - foreach (var syntaxTree in context.Compilation.SyntaxTrees) - { - var semanticModel = context.Compilation.GetSemanticModel(syntaxTree); - foreach (var node in syntaxTree.GetRoot().DescendantNodes()) - { - var symbol = semanticModel.GetDeclaredSymbol(node); - if (symbol != null && symbol.GetAttributes().Any(attr => attr.AttributeClass?.Name == nameof(DecomposeAttribute))) - { - switch (symbol) - { - case IAssemblySymbol assemblySymbol: - if (assemblySymbol.Constructors.Any(c => c.Parameters.Length == 2 && - c.Parameters[0].Type?.SpecialType == SpecialType.System_Type && - c.Parameters[1].Type?.SpecialType == SpecialType.System_String)) - { - assembliesToDecompose.Add(assemblySymbol); - } - break; - case INamedTypeSymbol namedTypeSymbol: - if (namedTypeSymbol.Constructors.Any(c => c.Parameters.Length == 0)) - { - typesToDecompose.Add(namedTypeSymbol); - } - break; - } - } - } - } + // Generate code for each type marked with the Decompose attribute + foreach (var type in typesToDecompose) + { + var ns = type.ContainingNamespace.ToDisplayString(); + var interfaces = new List(); - // Generate code for each type marked with the Decompose attribute - foreach (var type in typesToDecompose) + // Generate an interface for each public property and method + foreach (var member in type.GetMembers().Where(m => m.DeclaredAccessibility == Accessibility.Public)) { - var ns = type.ContainingNamespace.ToDisplayString(); - var interfaces = new List(); - - // Generate an interface for each public property and method - foreach (var member in type.GetMembers().Where(m => m.DeclaredAccessibility == Accessibility.Public)) - { - var interfaceName = $\"I{member.Name}\"; + var interfaceName = $\"I{member.Name}\"; var interfaceDeclaration = new CodeTypeDeclaration(interfaceName) { IsInterface = true, @@ -144,73 +145,75 @@ public void Execute(GeneratorExecutionContext context) } }; - if (member is IPropertySymbol propertySymbol) + if (member is IPropertySymbol propertySymbol) + { + var propertyDeclaration = new CodeMemberProperty() { - var propertyDeclaration = new CodeMemberProperty() - { - Name = propertySymbol.Name, - Type = new CodeTypeReference(propertySymbol.Type), - Attributes = MemberAttributes.None, - HasGet = true, - HasSet = false - }; + Name = propertySymbol.Name, + Type = new CodeTypeReference(propertySymbol.Type), + Attributes = MemberAttributes.None, + HasGet = true, + HasSet = false + }; - interfaceDeclaration.Members.Add(propertyDeclaration); - } - else if (member is IMethodSymbol methodSymbol) + interfaceDeclaration.Members.Add(propertyDeclaration); + } + else if (member is IMethodSymbol methodSymbol) + { + var methodDeclaration = new CodeMemberMethod() { - var methodDeclaration = new CodeMemberMethod() - { - Name = methodSymbol.Name, - ReturnType = new CodeTypeReference(methodSymbol.ReturnType), - Attributes = MemberAttributes.None, - ReturnTypeCustomAttributes = { new CodeAttributeDeclaration(typeof(System.Runtime.CompilerServices.AsyncStateMachineAttribute).FullName) } - }; - - foreach (var parameter in methodSymbol.Parameters) - { - methodDeclaration.Parameters.Add(new CodeParameterDeclarationExpression(parameter.Type, parameter.Name)); - } + Name = methodSymbol.Name, + ReturnType = new CodeTypeReference(methodSymbol.ReturnType), + Attributes = MemberAttributes.None, + ReturnTypeCustomAttributes = { new CodeAttributeDeclaration(typeof(System.Runtime.CompilerServices.AsyncStateMachineAttribute).FullName) } + }; - interfaceDeclaration.Members.Add(methodDeclaration); + foreach (var parameter in methodSymbol.Parameters) + { + methodDeclaration.Parameters.Add(new CodeParameterDeclarationExpression(parameter.Type, parameter.Name)); } - interfaces.Add(interfaceDeclaration); + interfaceDeclaration.Members.Add(methodDeclaration); } - // Add the interfaces to the code namespace - var codeNamespace = new CodeNamespace(ns); - foreach (var interfaceDeclaration in interfaces) - { - codeNamespace.Types.Add(interfaceDeclaration); - } + interfaces.Add(interfaceDeclaration); + } - // Generate the C# code and add it to the context - var provider = new CSharpCodeProvider(); - var options = new CodeGeneratorOptions() { BracingStyle = \"C\" }; + // Add the interfaces to the code namespace + var codeNamespace = new CodeNamespace(ns); + foreach (var interfaceDeclaration in interfaces) + { + codeNamespace.Types.Add(interfaceDeclaration); + } + + // Generate the C# code and add it to the context + var provider = new CSharpCodeProvider(); + var options = new CodeGeneratorOptions() + { + BracingStyle = \"C\" }; var code = new CodeCompileUnit(); - code.Namespaces.Add(codeNamespace); + code.Namespaces.Add(codeNamespace); - using var writer = new StringWriter(); - provider.GenerateCodeFromCompileUnit(code, writer, options); - var sourceCode = writer.ToString(); + using var writer = new StringWriter(); + provider.GenerateCodeFromCompileUnit(code, writer, options); + var sourceCode = writer.ToString(); - context.AddSource($\"{type.Name}_Interfaces.cs\", SourceText.From(sourceCode, Encoding.UTF8)); + context.AddSource($\"{type.Name}_Interfaces.cs\", SourceText.From(sourceCode, Encoding.UTF8)); } - // Generate code for each assembly marked with the Decompose attribute - foreach (var assembly in assembliesToDecompose) - { - var attribute = assembly.GetAttributes().FirstOrDefault(attr => attr.AttributeClass?.Name == nameof(DecomposeAttribute)); - var ns = attribute.ConstructorArguments[1].Value.ToString(); - var interfaces = new List(); + // Generate code for each assembly marked with the Decompose attribute + foreach (var assembly in assembliesToDecompose) + { + var attribute = assembly.GetAttributes().FirstOrDefault(attr => attr.AttributeClass?.Name == nameof(DecomposeAttribute)); + var ns = attribute.ConstructorArguments[1].Value.ToString(); + var interfaces = new List(); - // Generate an interface for each public property and method of each type in the assembly - foreach (var type in assembly.GlobalNamespace.GetNamespaceMembers().SelectMany(n => n.GetTypeMembers())) + // Generate an interface for each public property and method of each type in the assembly + foreach (var type in assembly.GlobalNamespace.GetNamespaceMembers().SelectMany(n => n.GetTypeMembers())) + { + foreach (var member in type.GetMembers().Where(m => m.DeclaredAccessibility == Accessibility.Public)) { - foreach (var member in type.GetMembers().Where(m => m.DeclaredAccessibility == Accessibility.Public)) - { - var interfaceName = $\"I{type.Name}_{member.Name}\"; + var interfaceName = $\"I{type.Name}_{member.Name}\"; var interfaceDeclaration = new CodeTypeDeclaration(interfaceName) { IsInterface = true, @@ -224,66 +227,69 @@ public void Execute(GeneratorExecutionContext context) } }; - if (member is IPropertySymbol propertySymbol) + if (member is IPropertySymbol propertySymbol) + { + var propertyDeclaration = new CodeMemberProperty() { - var propertyDeclaration = new CodeMemberProperty() - { - Name = propertySymbol.Name, - Type = new CodeTypeReference(propertySymbol.Type), - Attributes = MemberAttributes.None, - HasGet = true, - HasSet = false - }; + Name = propertySymbol.Name, + Type = new CodeTypeReference(propertySymbol.Type), + Attributes = MemberAttributes.None, + HasGet = true, + HasSet = false + }; - interfaceDeclaration.Members.Add(propertyDeclaration); - } - else if (member is IMethodSymbol methodSymbol) + interfaceDeclaration.Members.Add(propertyDeclaration); + } + else if (member is IMethodSymbol methodSymbol) + { + var methodDeclaration = new CodeMemberMethod() { - var methodDeclaration = new CodeMemberMethod() - { - Name = methodSymbol.Name, - ReturnType = new CodeTypeReference(methodSymbol.ReturnType), - Attributes = MemberAttributes.None, - ReturnTypeCustomAttributes = { new CodeAttributeDeclaration(typeof(System.Runtime.CompilerServices.AsyncStateMachineAttribute).FullName) } - }; - - foreach (var parameter in methodSymbol.Parameters) - { - methodDeclaration.Parameters.Add(new CodeParameterDeclarationExpression(parameter.Type, parameter.Name)); - } + Name = methodSymbol.Name, + ReturnType = new CodeTypeReference(methodSymbol.ReturnType), + Attributes = MemberAttributes.None, + ReturnTypeCustomAttributes = { new CodeAttributeDeclaration(typeof(System.Runtime.CompilerServices.AsyncStateMachineAttribute).FullName) } + }; - interfaceDeclaration.Members.Add(methodDeclaration); + foreach (var parameter in methodSymbol.Parameters) + { + methodDeclaration.Parameters.Add(new CodeParameterDeclarationExpression(parameter.Type, parameter.Name)); } - interfaces.Add(interfaceDeclaration); + interfaceDeclaration.Members.Add(methodDeclaration); } - } - // Add the interfaces to the code namespace - var codeNamespace = new CodeNamespace(ns); - foreach (var interfaceDeclaration in interfaces) - { - codeNamespace.Types.Add(interfaceDeclaration); + interfaces.Add(interfaceDeclaration); } + } - // Generate the C# code and add it to the context - var provider = new CSharpCodeProvider(); - var options = new CodeGeneratorOptions() { BracingStyle = \"C\" }; + // Add the interfaces to the code namespace + var codeNamespace = new CodeNamespace(ns); + foreach (var interfaceDeclaration in interfaces) + { + codeNamespace.Types.Add(interfaceDeclaration); + } + + // Generate the C# code and add it to the context + var provider = new CSharpCodeProvider(); + var options = new CodeGeneratorOptions() + { + BracingStyle = \"C\" }; var code = new CodeCompileUnit(); - code.Namespaces.Add(codeNamespace); + code.Namespaces.Add(codeNamespace); - using var writer = new StringWriter(); - provider.GenerateCodeFromCompileUnit(code, writer, options); - var sourceCode = writer.ToString(); + using var writer = new StringWriter(); + provider.GenerateCodeFromCompileUnit(code, writer, options); + var sourceCode = writer.ToString(); - context.AddSource($\"{ns}_Interfaces.cs\", SourceText.From(sourceCode, Encoding.UTF8)); + context.AddSource($\"{ns}_Interfaces.cs\", SourceText.From(sourceCode, Encoding.UTF8)); } - } +} } ``` -This updated implementation should work with the current public API surface of Roslyn. Note that the `GeneratorExecutionContext` class does not support incremental generation, so the generator will be run for all compilation invocations, regardless of whether any changes were made to the source code."), - new ChatMessage(ChatRole.User, @"Why did you lie to me the first time? Are you incapable of building an IIncrementalGenerator?"), +This updated implementation should work with the current public API surface of Roslyn.Note that the `GeneratorExecutionContext` class does not support incremental generation, so the generator will be run for all compilation invocations, regardless of whether any changes were made to the source code."), + + new ChatMessage(ChatRole.User, @"Why did you lie to me the first time? Are you incapable of building an IIncrementalGenerator?"), new ChatMessage(ChatRole.Assistant, @"This model's maximum context length is 8192 tokens. However, you requested 8987 tokens (4987 in the messages, 4000 in the completion). Please reduce the length of the messages or completion."), new ChatMessage(ChatRole.User, @"The name MemberAttributes does not exis i the current context: @@ -308,21 +314,22 @@ public void Execute(GeneratorExecutionContext context) // ### If streaming is not selected Response responseWithoutStream = await client.GetChatCompletionsAsync( - "MyFirstOpenAI", - new ChatCompletionsOptions() - { - Messages = - { - new ChatMessage(ChatRole.System, @"Yo are an expert software architect, fluent in C#, TypeScript, Python, PowerShell, and MSIL. You are knowledgeable on the latest software design and security concepts and an expert at designing ""clean code."" Your job is to assist people with coding problems they have."), - new ChatMessage(ChatRole.User, @"Where/how is IncrementalGeneratorExecutionContext defined?"), - new ChatMessage(ChatRole.Assistant, @"The `IncrementalGeneratorExecutionContext` is part of the `Microsoft.CodeAnalysis` namespace, which is included in the `Microsoft.CodeAnalysis.Analyzers` NuGet package. You can install this package via the NuGet Package Manager or by adding the following line to your project file: + "MyFirstOpenAI", + new ChatCompletionsOptions() + { + Messages = + { + new ChatMessage(ChatRole.System, @"Yo are an expert software architect, fluent in C#, TypeScript, Python, PowerShell, and MSIL. You are knowledgeable on the latest software design and security concepts and an expert at designing ""clean code."" Your job is to assist people with coding problems they have."), + new ChatMessage(ChatRole.User, @"Where/how is IncrementalGeneratorExecutionContext defined?"), + new ChatMessage(ChatRole.Assistant, @"The `IncrementalGeneratorExecutionContext` is part of the `Microsoft.CodeAnalysis` namespace, which is included in the `Microsoft.CodeAnalysis.Analyzers` NuGet package. You can install this package via the NuGet Package Manager or by adding the following line to your project file: ```xml ``` Once you have the package installed, you can reference the `Microsoft.CodeAnalysis` namespace and access the `IncrementalGeneratorExecutionContext` class in your code."), - new ChatMessage(ChatRole.User, @"No it isn't."), + + new ChatMessage(ChatRole.User, @"No it isn't."), new ChatMessage(ChatRole.Assistant, @"I apologize for the confusion. The `IncrementalGeneratorExecutionContext` class is actually part of the `Microsoft.CodeAnalysis` namespace, but it is not currently available in the public API surface of the .NET Compiler Platform (Roslyn). The class was introduced in preview versions of Roslyn, but it was removed before the final release. If you want to use the `IncrementalGeneratorExecutionContext` class, you'll need to use a preview version of Roslyn, which may not be suitable for production use. Alternatively, you can use the `GeneratorExecutionContext` class, which is part of the public API surface and provides similar functionality to the `IncrementalGeneratorExecutionContext`. @@ -358,75 +365,75 @@ public class MyGenerator : ISourceGenerator private const string DecomposerGeneratorVersion = \"1.0.0\"; public void Initialize(GeneratorInitializationContext context) +{ + // No initialization needed +} + +public void Execute(GeneratorExecutionContext context) +{ + var typesToDecompose = new List(); + var assembliesToDecompose = new List(); + + // Find all types and assemblies marked with the Decompose attribute + foreach (var reference in context.Compilation.References) { - // No initialization needed + var symbol = context.Compilation.GetAssemblyOrModuleSymbol(reference); + if (symbol != null && symbol.GetAttributes().Any(attr => attr.AttributeClass?.Name == nameof(DecomposeAttribute))) + { + switch (symbol) + { + case IAssemblySymbol assembly: + assembliesToDecompose.Add(assembly); + break; + case INamedTypeSymbol type: + if (type.Constructors.Any(c => c.Parameters.Length == 0)) + { + typesToDecompose.Add(type); + } + break; + } + } } - public void Execute(GeneratorExecutionContext context) + foreach (var syntaxTree in context.Compilation.SyntaxTrees) { - var typesToDecompose = new List(); - var assembliesToDecompose = new List(); - - // Find all types and assemblies marked with the Decompose attribute - foreach (var reference in context.Compilation.References) + var semanticModel = context.Compilation.GetSemanticModel(syntaxTree); + foreach (var node in syntaxTree.GetRoot().DescendantNodes()) { - var symbol = context.Compilation.GetAssemblyOrModuleSymbol(reference); + var symbol = semanticModel.GetDeclaredSymbol(node); if (symbol != null && symbol.GetAttributes().Any(attr => attr.AttributeClass?.Name == nameof(DecomposeAttribute))) { switch (symbol) { - case IAssemblySymbol assembly: - assembliesToDecompose.Add(assembly); + case IAssemblySymbol assemblySymbol: + if (assemblySymbol.Constructors.Any(c => c.Parameters.Length == 2 && + c.Parameters[0].Type?.SpecialType == SpecialType.System_Type && + c.Parameters[1].Type?.SpecialType == SpecialType.System_String)) + { + assembliesToDecompose.Add(assemblySymbol); + } break; - case INamedTypeSymbol type: - if (type.Constructors.Any(c => c.Parameters.Length == 0)) + case INamedTypeSymbol namedTypeSymbol: + if (namedTypeSymbol.Constructors.Any(c => c.Parameters.Length == 0)) { - typesToDecompose.Add(type); + typesToDecompose.Add(namedTypeSymbol); } break; } } } + } - foreach (var syntaxTree in context.Compilation.SyntaxTrees) - { - var semanticModel = context.Compilation.GetSemanticModel(syntaxTree); - foreach (var node in syntaxTree.GetRoot().DescendantNodes()) - { - var symbol = semanticModel.GetDeclaredSymbol(node); - if (symbol != null && symbol.GetAttributes().Any(attr => attr.AttributeClass?.Name == nameof(DecomposeAttribute))) - { - switch (symbol) - { - case IAssemblySymbol assemblySymbol: - if (assemblySymbol.Constructors.Any(c => c.Parameters.Length == 2 && - c.Parameters[0].Type?.SpecialType == SpecialType.System_Type && - c.Parameters[1].Type?.SpecialType == SpecialType.System_String)) - { - assembliesToDecompose.Add(assemblySymbol); - } - break; - case INamedTypeSymbol namedTypeSymbol: - if (namedTypeSymbol.Constructors.Any(c => c.Parameters.Length == 0)) - { - typesToDecompose.Add(namedTypeSymbol); - } - break; - } - } - } - } + // Generate code for each type marked with the Decompose attribute + foreach (var type in typesToDecompose) + { + var ns = type.ContainingNamespace.ToDisplayString(); + var interfaces = new List(); - // Generate code for each type marked with the Decompose attribute - foreach (var type in typesToDecompose) + // Generate an interface for each public property and method + foreach (var member in type.GetMembers().Where(m => m.DeclaredAccessibility == Accessibility.Public)) { - var ns = type.ContainingNamespace.ToDisplayString(); - var interfaces = new List(); - - // Generate an interface for each public property and method - foreach (var member in type.GetMembers().Where(m => m.DeclaredAccessibility == Accessibility.Public)) - { - var interfaceName = $\"I{member.Name}\"; + var interfaceName = $\"I{member.Name}\"; var interfaceDeclaration = new CodeTypeDeclaration(interfaceName) { IsInterface = true, @@ -440,73 +447,75 @@ public void Execute(GeneratorExecutionContext context) } }; - if (member is IPropertySymbol propertySymbol) + if (member is IPropertySymbol propertySymbol) + { + var propertyDeclaration = new CodeMemberProperty() { - var propertyDeclaration = new CodeMemberProperty() - { - Name = propertySymbol.Name, - Type = new CodeTypeReference(propertySymbol.Type), - Attributes = MemberAttributes.None, - HasGet = true, - HasSet = false - }; + Name = propertySymbol.Name, + Type = new CodeTypeReference(propertySymbol.Type), + Attributes = MemberAttributes.None, + HasGet = true, + HasSet = false + }; - interfaceDeclaration.Members.Add(propertyDeclaration); - } - else if (member is IMethodSymbol methodSymbol) + interfaceDeclaration.Members.Add(propertyDeclaration); + } + else if (member is IMethodSymbol methodSymbol) + { + var methodDeclaration = new CodeMemberMethod() { - var methodDeclaration = new CodeMemberMethod() - { - Name = methodSymbol.Name, - ReturnType = new CodeTypeReference(methodSymbol.ReturnType), - Attributes = MemberAttributes.None, - ReturnTypeCustomAttributes = { new CodeAttributeDeclaration(typeof(System.Runtime.CompilerServices.AsyncStateMachineAttribute).FullName) } - }; - - foreach (var parameter in methodSymbol.Parameters) - { - methodDeclaration.Parameters.Add(new CodeParameterDeclarationExpression(parameter.Type, parameter.Name)); - } + Name = methodSymbol.Name, + ReturnType = new CodeTypeReference(methodSymbol.ReturnType), + Attributes = MemberAttributes.None, + ReturnTypeCustomAttributes = { new CodeAttributeDeclaration(typeof(System.Runtime.CompilerServices.AsyncStateMachineAttribute).FullName) } + }; - interfaceDeclaration.Members.Add(methodDeclaration); + foreach (var parameter in methodSymbol.Parameters) + { + methodDeclaration.Parameters.Add(new CodeParameterDeclarationExpression(parameter.Type, parameter.Name)); } - interfaces.Add(interfaceDeclaration); + interfaceDeclaration.Members.Add(methodDeclaration); } - // Add the interfaces to the code namespace - var codeNamespace = new CodeNamespace(ns); - foreach (var interfaceDeclaration in interfaces) - { - codeNamespace.Types.Add(interfaceDeclaration); - } + interfaces.Add(interfaceDeclaration); + } - // Generate the C# code and add it to the context - var provider = new CSharpCodeProvider(); - var options = new CodeGeneratorOptions() { BracingStyle = \"C\" }; + // Add the interfaces to the code namespace + var codeNamespace = new CodeNamespace(ns); + foreach (var interfaceDeclaration in interfaces) + { + codeNamespace.Types.Add(interfaceDeclaration); + } + + // Generate the C# code and add it to the context + var provider = new CSharpCodeProvider(); + var options = new CodeGeneratorOptions() + { + BracingStyle = \"C\" }; var code = new CodeCompileUnit(); - code.Namespaces.Add(codeNamespace); + code.Namespaces.Add(codeNamespace); - using var writer = new StringWriter(); - provider.GenerateCodeFromCompileUnit(code, writer, options); - var sourceCode = writer.ToString(); + using var writer = new StringWriter(); + provider.GenerateCodeFromCompileUnit(code, writer, options); + var sourceCode = writer.ToString(); - context.AddSource($\"{type.Name}_Interfaces.cs\", SourceText.From(sourceCode, Encoding.UTF8)); + context.AddSource($\"{type.Name}_Interfaces.cs\", SourceText.From(sourceCode, Encoding.UTF8)); } - // Generate code for each assembly marked with the Decompose attribute - foreach (var assembly in assembliesToDecompose) - { - var attribute = assembly.GetAttributes().FirstOrDefault(attr => attr.AttributeClass?.Name == nameof(DecomposeAttribute)); - var ns = attribute.ConstructorArguments[1].Value.ToString(); - var interfaces = new List(); + // Generate code for each assembly marked with the Decompose attribute + foreach (var assembly in assembliesToDecompose) + { + var attribute = assembly.GetAttributes().FirstOrDefault(attr => attr.AttributeClass?.Name == nameof(DecomposeAttribute)); + var ns = attribute.ConstructorArguments[1].Value.ToString(); + var interfaces = new List(); - // Generate an interface for each public property and method of each type in the assembly - foreach (var type in assembly.GlobalNamespace.GetNamespaceMembers().SelectMany(n => n.GetTypeMembers())) + // Generate an interface for each public property and method of each type in the assembly + foreach (var type in assembly.GlobalNamespace.GetNamespaceMembers().SelectMany(n => n.GetTypeMembers())) + { + foreach (var member in type.GetMembers().Where(m => m.DeclaredAccessibility == Accessibility.Public)) { - foreach (var member in type.GetMembers().Where(m => m.DeclaredAccessibility == Accessibility.Public)) - { - var interfaceName = $\"I{type.Name}_{member.Name}\"; + var interfaceName = $\"I{type.Name}_{member.Name}\"; var interfaceDeclaration = new CodeTypeDeclaration(interfaceName) { IsInterface = true, @@ -520,66 +529,69 @@ public void Execute(GeneratorExecutionContext context) } }; - if (member is IPropertySymbol propertySymbol) + if (member is IPropertySymbol propertySymbol) + { + var propertyDeclaration = new CodeMemberProperty() { - var propertyDeclaration = new CodeMemberProperty() - { - Name = propertySymbol.Name, - Type = new CodeTypeReference(propertySymbol.Type), - Attributes = MemberAttributes.None, - HasGet = true, - HasSet = false - }; + Name = propertySymbol.Name, + Type = new CodeTypeReference(propertySymbol.Type), + Attributes = MemberAttributes.None, + HasGet = true, + HasSet = false + }; - interfaceDeclaration.Members.Add(propertyDeclaration); - } - else if (member is IMethodSymbol methodSymbol) + interfaceDeclaration.Members.Add(propertyDeclaration); + } + else if (member is IMethodSymbol methodSymbol) + { + var methodDeclaration = new CodeMemberMethod() { - var methodDeclaration = new CodeMemberMethod() - { - Name = methodSymbol.Name, - ReturnType = new CodeTypeReference(methodSymbol.ReturnType), - Attributes = MemberAttributes.None, - ReturnTypeCustomAttributes = { new CodeAttributeDeclaration(typeof(System.Runtime.CompilerServices.AsyncStateMachineAttribute).FullName) } - }; - - foreach (var parameter in methodSymbol.Parameters) - { - methodDeclaration.Parameters.Add(new CodeParameterDeclarationExpression(parameter.Type, parameter.Name)); - } + Name = methodSymbol.Name, + ReturnType = new CodeTypeReference(methodSymbol.ReturnType), + Attributes = MemberAttributes.None, + ReturnTypeCustomAttributes = { new CodeAttributeDeclaration(typeof(System.Runtime.CompilerServices.AsyncStateMachineAttribute).FullName) } + }; - interfaceDeclaration.Members.Add(methodDeclaration); + foreach (var parameter in methodSymbol.Parameters) + { + methodDeclaration.Parameters.Add(new CodeParameterDeclarationExpression(parameter.Type, parameter.Name)); } - interfaces.Add(interfaceDeclaration); + interfaceDeclaration.Members.Add(methodDeclaration); } - } - // Add the interfaces to the code namespace - var codeNamespace = new CodeNamespace(ns); - foreach (var interfaceDeclaration in interfaces) - { - codeNamespace.Types.Add(interfaceDeclaration); + interfaces.Add(interfaceDeclaration); } + } - // Generate the C# code and add it to the context - var provider = new CSharpCodeProvider(); - var options = new CodeGeneratorOptions() { BracingStyle = \"C\" }; + // Add the interfaces to the code namespace + var codeNamespace = new CodeNamespace(ns); + foreach (var interfaceDeclaration in interfaces) + { + codeNamespace.Types.Add(interfaceDeclaration); + } + + // Generate the C# code and add it to the context + var provider = new CSharpCodeProvider(); + var options = new CodeGeneratorOptions() + { + BracingStyle = \"C\" }; var code = new CodeCompileUnit(); - code.Namespaces.Add(codeNamespace); + code.Namespaces.Add(codeNamespace); - using var writer = new StringWriter(); - provider.GenerateCodeFromCompileUnit(code, writer, options); - var sourceCode = writer.ToString(); + using var writer = new StringWriter(); + provider.GenerateCodeFromCompileUnit(code, writer, options); + var sourceCode = writer.ToString(); - context.AddSource($\"{ns}_Interfaces.cs\", SourceText.From(sourceCode, Encoding.UTF8)); + context.AddSource($\"{ns}_Interfaces.cs\", SourceText.From(sourceCode, Encoding.UTF8)); } - } +} } ``` -This updated implementation should work with the current public API surface of Roslyn. Note that the `GeneratorExecutionContext` class does not support incremental generation, so the generator will be run for all compilation invocations, regardless of whether any changes were made to the source code."), - new ChatMessage(ChatRole.User, @"Why did you lie to me the first time? Are you incapable of building an IIncrementalGenerator?"), +This updated implementation should work with the current public API surface of Roslyn.Note that the `GeneratorExecutionContext` class does not support incremental generation, so the generator will be run for all compilation invocations, regardless of whether any changes were made to the source code."), + + new ChatMessage(ChatRole.User, @"Why did you lie to me the first time? Are you incapable of building an IIncrementalGenerator?"), new ChatMessage(ChatRole.Assistant, @"This model's maximum context length is 8192 tokens. However, you requested 8987 tokens (4987 in the messages, 4000 in the completion). Please reduce the length of the messages or completion."), new ChatMessage(ChatRole.User, @"The name MemberAttributes does not exis i the current context: diff --git a/InterfaceGenerator/Constants.cs b/InterfaceGenerator/Constants.cs index 6b3d989..6e8cf5f 100644 --- a/InterfaceGenerator/Constants.cs +++ b/InterfaceGenerator/Constants.cs @@ -35,18 +35,18 @@ public static class Constants """ using System; - [AttributeUsage(AttributeTargets.Interface)] - internal sealed class GenerateInterfaceAttribute : Attribute - { - public Type Type { get; } - - public GenerateInterfaceAttribute (Type type) - { - { - Type = type; - } - } - } + [AttributeUsage(AttributeTargets.Interface)] +internal sealed class GenerateInterfaceAttribute : Attribute +{ + public Type Type { get; } + + public GenerateInterfaceAttribute(Type type) + { + { + Type = type; + } + } +} """; public const string InterfaceDeclaration = @@ -63,33 +63,39 @@ public GenerateInterfaceAttribute (Type type) namespace {{ namespace }} { - public partial interface {{ interface_name }} - { - {{ members }} - } + public partial interface {{ interface_name +} +} +{ + { { members } } +} } """; - public static readonly Scriban.Template InterfaceDeclarationTemplate = Scriban.Template.Parse(InterfaceDeclaration); - - public const string MethodDeclaration = - """ - {{ return_type }} {{ method_name }}({{ parameters }}) {{ type_constraints }}; - """; - - public static readonly Scriban.Template MethodDeclarationTemplate = Scriban.Template.Parse(MethodDeclaration); - - public const string MethodParameter = - """ - {{ type }} {{ name }} - """; - - public static readonly Scriban.Template MethodParameterTemplate = Scriban.Template.Parse(MethodParameter); - - public const string PropertyDeclaration = - """ - {{ type }} {{ name }} { {{~ if is_gettable ~}} get; {{~ end ~}} {{~ if is_settable ~}} set; {{~ end ~}} } - """; + public static readonly Scriban.Template InterfaceDeclarationTemplate = Scriban.Template.Parse(InterfaceDeclaration); + +public const string MethodDeclaration = +""" + { { return_type } } +{ { method_name } } ({ { parameters } }) { { type_constraints } }; +"""; + + public static readonly Scriban.Template MethodDeclarationTemplate = Scriban.Template.Parse(MethodDeclaration); + +public const string MethodParameter = +""" + { { type } } +{ { name } } +"""; + + public static readonly Scriban.Template MethodParameterTemplate = Scriban.Template.Parse(MethodParameter); + +public const string PropertyDeclaration = +""" + { { type } } +{ { name } } +{ { { ~ if is_gettable ~} } get; { { ~end ~} } { { ~ if is_settable ~} } set; { { ~end ~} } } +"""; public static readonly Scriban.Template PropertyDeclarationTemplate = Scriban.Template.Parse(PropertyDeclaration); diff --git a/InterfaceGenerator/InterfaceGenerator.cs b/InterfaceGenerator/InterfaceGenerator.cs index 98d7b42..295bdcd 100644 --- a/InterfaceGenerator/InterfaceGenerator.cs +++ b/InterfaceGenerator/InterfaceGenerator.cs @@ -103,25 +103,25 @@ SemanticModel semanticModel .OfType() .Where(p => p.DeclaredAccessibility == Accessibility.Public) .Select( - p => p.ToDisplayString(Constants.SymbolDisplayFormat) - // PropertyDeclarationTemplate.Render( - // new PropertyDeclarationModel( - // "public", - // p.Type.ToDisplayString(), - // p.Name, - // p.GetMethod != null, - // p.SetMethod != null, - // p.IsIndexer - // ? Join( - // ", ", - // p.Parameters.Select( - // p => - // $"{p.Type.ToDisplayString()} {p.Name}" - // ) - // ) - // : "" - // ) - // ) + p => p.ToDisplayString(Constants.SymbolDisplayFormat) + // PropertyDeclarationTemplate.Render( + // new PropertyDeclarationModel( + // "public", + // p.Type.ToDisplayString(), + // p.Name, + // p.GetMethod != null, + // p.SetMethod != null, + // p.IsIndexer + // ? Join( + // ", ", + // p.Parameters.Select( + // p => + // $"{p.Type.ToDisplayString()} {p.Name}" + // ) + // ) + // : "" + // ) + // ) ) ) + Environment.NewLine diff --git a/InterfaceGenerator/InterfaceGeneratorConstants.cs b/InterfaceGenerator/InterfaceGeneratorConstants.cs index c5be265..a954fb2 100644 --- a/InterfaceGenerator/InterfaceGeneratorConstants.cs +++ b/InterfaceGenerator/InterfaceGeneratorConstants.cs @@ -36,16 +36,18 @@ public static class Constants using System; [AttributeUsage(AttributeTargets.Interface)] - internal sealed class {{{GenerateInterfaceAttributeName}}} : Attribute - { - public Type Type { get; } - - public {{{GenerateInterfaceAttributeName}}} (Type type) - { - { - Type = type; - } - } + internal sealed class {{{GenerateInterfaceAttributeName +}}} : Attribute +{ + public Type Type { get; } + +public +{ { { GenerateInterfaceAttributeName} } } (Type type) + { + { + Type = type; + } +} } """; @@ -63,72 +65,74 @@ internal sealed class {{{GenerateInterfaceAttributeName}}} : Attribute namespace {{ namespace }} { - public partial interface {{ interface_name }} - { - {{ members }} - } + public partial interface {{ interface_name +}} + { + { { members } } +} } """; public static readonly Scriban.Template InterfaceDeclarationTemplate = - Scriban.Template.Parse(InterfaceDeclaration); - - public const string MethodDeclaration = "{{ full_definition }};"; - - public static readonly Scriban.Template MethodDeclarationTemplate = Scriban.Template.Parse( - MethodDeclaration - ); - - public const string MethodParameter = """ - {{ type }} {{ name }} - """; + Scriban.Template.Parse(InterfaceDeclaration); + +public const string MethodDeclaration = "{{ full_definition }};"; + +public static readonly Scriban.Template MethodDeclarationTemplate = Scriban.Template.Parse( + MethodDeclaration +); + +public const string MethodParameter = """ + { { type } } +{ { name } } +"""; public static readonly Scriban.Template MethodParameterTemplate = Scriban.Template.Parse( MethodParameter - ); - - public const string PropertyDeclaration = - "{{ type }} {{ if is_indexed }}this[ {{ indexers }}] {{ else }} {{ name }} {{ end }} { {{ if is_gettable }} get; {{ end }} {{ if is_settable }} set; {{ end }} }"; - - public static readonly Scriban.Template PropertyDeclarationTemplate = - Scriban.Template.Parse(PropertyDeclaration); - - // static Constants() - // { - // if(!InterfaceDeclarationTemplate.HasErrors) - // throw new Exception(string.Join(Environment.NewLine, InterfaceDeclarationTemplate.Messages.Select(m => m.ToString()))); - // } - - public static readonly SymbolDisplayFormat SymbolDisplayFormat = - new( - SymbolDisplayGlobalNamespaceStyle.Included, - SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, - SymbolDisplayGenericsOptions.IncludeTypeParameters - | SymbolDisplayGenericsOptions.IncludeVariance - | SymbolDisplayGenericsOptions.IncludeTypeConstraints, - SymbolDisplayMemberOptions.IncludeConstantValue - | SymbolDisplayMemberOptions.IncludeExplicitInterface - | SymbolDisplayMemberOptions.IncludeModifiers - | SymbolDisplayMemberOptions.IncludeParameters - | SymbolDisplayMemberOptions.IncludeRef - | SymbolDisplayMemberOptions.IncludeType, - SymbolDisplayDelegateStyle.NameAndSignature, - SymbolDisplayExtensionMethodStyle.Default, - SymbolDisplayParameterOptions.IncludeExtensionThis - | SymbolDisplayParameterOptions.IncludeName - | SymbolDisplayParameterOptions.IncludeParamsRefOut - | SymbolDisplayParameterOptions.IncludeType - | SymbolDisplayParameterOptions.IncludeType - | SymbolDisplayParameterOptions.IncludeDefaultValue - | SymbolDisplayParameterOptions.IncludeOptionalBrackets, - SymbolDisplayPropertyStyle.ShowReadWriteDescriptor, - miscellaneousOptions: SymbolDisplayMiscellaneousOptions.UseSpecialTypes - | SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers - | SymbolDisplayMiscellaneousOptions.UseAsterisksInMultiDimensionalArrays - | SymbolDisplayMiscellaneousOptions.UseErrorTypeSymbolName - | SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier - | SymbolDisplayMiscellaneousOptions.IncludeNotNullableReferenceTypeModifier - ); + ); + +public const string PropertyDeclaration = + "{{ type }} {{ if is_indexed }}this[ {{ indexers }}] {{ else }} {{ name }} {{ end }} { {{ if is_gettable }} get; {{ end }} {{ if is_settable }} set; {{ end }} }"; + +public static readonly Scriban.Template PropertyDeclarationTemplate = + Scriban.Template.Parse(PropertyDeclaration); + +// static Constants() +// { +// if(!InterfaceDeclarationTemplate.HasErrors) +// throw new Exception(string.Join(Environment.NewLine, InterfaceDeclarationTemplate.Messages.Select(m => m.ToString()))); +// } + +public static readonly SymbolDisplayFormat SymbolDisplayFormat = + new( + SymbolDisplayGlobalNamespaceStyle.Included, + SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces, + SymbolDisplayGenericsOptions.IncludeTypeParameters + | SymbolDisplayGenericsOptions.IncludeVariance + | SymbolDisplayGenericsOptions.IncludeTypeConstraints, + SymbolDisplayMemberOptions.IncludeConstantValue + | SymbolDisplayMemberOptions.IncludeExplicitInterface + | SymbolDisplayMemberOptions.IncludeModifiers + | SymbolDisplayMemberOptions.IncludeParameters + | SymbolDisplayMemberOptions.IncludeRef + | SymbolDisplayMemberOptions.IncludeType, + SymbolDisplayDelegateStyle.NameAndSignature, + SymbolDisplayExtensionMethodStyle.Default, + SymbolDisplayParameterOptions.IncludeExtensionThis + | SymbolDisplayParameterOptions.IncludeName + | SymbolDisplayParameterOptions.IncludeParamsRefOut + | SymbolDisplayParameterOptions.IncludeType + | SymbolDisplayParameterOptions.IncludeType + | SymbolDisplayParameterOptions.IncludeDefaultValue + | SymbolDisplayParameterOptions.IncludeOptionalBrackets, + SymbolDisplayPropertyStyle.ShowReadWriteDescriptor, + miscellaneousOptions: SymbolDisplayMiscellaneousOptions.UseSpecialTypes + | SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers + | SymbolDisplayMiscellaneousOptions.UseAsterisksInMultiDimensionalArrays + | SymbolDisplayMiscellaneousOptions.UseErrorTypeSymbolName + | SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier + | SymbolDisplayMiscellaneousOptions.IncludeNotNullableReferenceTypeModifier + ); } public record struct InterfaceGeneratorModel( @@ -137,35 +141,36 @@ public record struct InterfaceGeneratorModel( string Members, string TypeParameters, string TypeConstraints - ); - - public record struct MethodDeclarationModel( - string ReturnType, - string MethodName, - string Parameters, - string TypeConstraints, - string FullDefinition - ); - - public record struct MethodParameterModel(string Type, string Name); - - public record struct PropertyDeclarationModel( - string visibility, - string Type, - string Name, - bool IsGettable, - bool IsSettable, - string? Indexers = null - ) + ); + +public record struct MethodDeclarationModel( + string ReturnType, + string MethodName, + string Parameters, + string TypeConstraints, + string FullDefinition +); + +public record struct MethodParameterModel(string Type, string Name); + +public record struct PropertyDeclarationModel( + string visibility, + string Type, + string Name, + bool IsGettable, + bool IsSettable, + string ? Indexers = null + +) { - public bool IsIndexed => !string.IsNullOrWhiteSpace(Indexers); - - public string Name { get; } = - (!string.IsNullOrWhiteSpace(Indexers) ? $"this[{Indexers}]" : Name); + public bool IsIndexed => !string.IsNullOrWhiteSpace(Indexers); + +public string Name { get; } = + (!string.IsNullOrWhiteSpace(Indexers) ? $"this[{Indexers}]" : Name); } - public static class Environment - { - public const string NewLine = "\r\n"; - } + public static class Environment +{ + public const string NewLine = "\r\n"; +} }