@@ -8,11 +8,10 @@ namespace AsyncTaskOrchestratorGenerator
88{
99 internal static class OutputGenerator
1010 {
11- public static ( string source , string className ) GenerateOutputs ( ( INamedTypeSymbol typeSymbol , SemanticModel semanticModel ) typeInfo ) {
11+ public static ( string source , string className ) GenerateClassOutputs ( ( INamedTypeSymbol typeSymbol , SemanticModel semanticModel ) typeInfo ) {
1212 var type = typeInfo . typeSymbol ;
1313 var semanticModel = typeInfo . semanticModel ;
14-
15- var constructorArguments = type . GetAttributes ( ) . First ( ( a ) => a . AttributeClass . Name == nameof ( AsyncTaskOrchestratorAttribute ) ) . ConstructorArguments ;
14+ var constructorArguments = GetAttributeConstructorArguments ( type ) ;
1615 var className = constructorArguments . First ( ) . Value . ToString ( ) ;
1716 var executeMethodName = constructorArguments . ElementAt ( 1 ) . Value . ToString ( ) ;
1817
@@ -50,11 +49,37 @@ namespace {type.ContainingNamespace.ToDisplayString()};
5049 return ( source , className ) ;
5150 }
5251
52+ private static System . Collections . Immutable . ImmutableArray < TypedConstant > GetAttributeConstructorArguments ( INamedTypeSymbol type ) {
53+ return type . GetAttributes ( ) . First ( ( a ) => a . AttributeClass . Name == nameof ( AsyncTaskOrchestratorAttribute ) ) . ConstructorArguments ;
54+ }
55+
56+ public static ( string source , string interfaceName ) GenerateInterfaceOutputs ( INamedTypeSymbol type ) {
57+ var constructorArguments = GetAttributeConstructorArguments ( type ) ;
58+ var className = constructorArguments . First ( ) . Value . ToString ( ) ;
59+ var executeMethodName = constructorArguments . ElementAt ( 1 ) . Value . ToString ( ) ;
60+ var interfaceName = $ "I{ className } ";
61+
62+ var accessModifier = type . DeclaredAccessibility . ToString ( ) . ToLower ( ) ;
63+ var executeMethod = GetExecuteMethod ( type ) ;
64+ var executeMethodAccessibility = executeMethod . DeclaredAccessibility . ToString ( ) . ToLower ( ) ;
65+ var formattedExecuteMethod = $ "{ executeMethodAccessibility } { executeMethod . ReturnType } { executeMethodName } ();";
66+
67+ var source =
68+ $@ "// <auto-generated/>
69+ #nullable restore
70+
71+ namespace { type . ContainingNamespace . ToDisplayString ( ) } ;
72+
73+ { accessModifier } interface { interfaceName }
74+ {{
75+ { formattedExecuteMethod }
76+ }}
77+ " ;
78+ return ( source , interfaceName ) ;
79+ }
80+
5381 private static ( ExecuteMethodSignatureData , Dictionary < string , TaskData > , TaskData ) CreateExecuteMethodData ( INamedTypeSymbol type , IEnumerable < IFieldSymbol > fields , string executeMethodName ) {
54- var executeMethod = type
55- . GetMembers ( )
56- . Where ( m => m is IMethodSymbol )
57- . First ( m => ( m as IMethodSymbol ) . MethodKind == MethodKind . Ordinary ) as IMethodSymbol ;
82+ var executeMethod = GetExecuteMethod ( type ) ;
5883 var statements = ( executeMethod . DeclaringSyntaxReferences . First ( ) . GetSyntax ( ) as MethodDeclarationSyntax ) . Body . Statements ;
5984 var variableStatements = statements . Remove ( statements . Last ( ) ) ;
6085
@@ -110,6 +135,13 @@ private static (ExecuteMethodSignatureData, Dictionary<string, TaskData>, TaskDa
110135 } , variableData . ToDictionary ( taskData => taskData . OutputName ) , finalTaskData ) ;
111136 }
112137
138+ private static IMethodSymbol GetExecuteMethod ( INamedTypeSymbol type ) {
139+ return type
140+ . GetMembers ( )
141+ . Where ( m => m is IMethodSymbol )
142+ . First ( m => ( m as IMethodSymbol ) . MethodKind == MethodKind . Ordinary ) as IMethodSymbol ;
143+ }
144+
113145 private static string FormatExecuteMethod ( ExecuteMethodSignatureData signatureData , Dictionary < string , TaskData > data , TaskData finalTaskData ) {
114146 var formattedTaskDeclarations = data . Select ( keyValue => {
115147 var item = keyValue . Value ;
0 commit comments