1
- namespace GqlPlus . Generating . Objects ;
1
+ using GqlPlus . Ast ;
2
2
3
- internal abstract class GenerateForObject < T >
4
- : GenerateForClass < T >
5
- where T : IGqlpObject
3
+ namespace GqlPlus . Generating . Objects ;
4
+
5
+ internal abstract class GenerateForObject < TObj , TBase , TField , TAlt >
6
+ : GenerateForClass < TObj >
7
+ where TObj : IGqlpObject < TBase , TField , TAlt >
8
+ where TBase : IGqlpObjBase
9
+ where TField : IGqlpObjField
10
+ where TAlt : IGqlpObjAlternate
6
11
{
7
- internal override IEnumerable < MapPair < string > > TypeMembers ( T ast , GeneratorContext context )
12
+ internal override IEnumerable < MapPair < string > > TypeMembers ( TObj ast , GeneratorContext context )
8
13
=> [ .. ast . Fields . Select ( FieldMember ( context ) ) , .. ast . Alternates . Select ( AlternateMember ( context ) ) ] ;
9
14
10
15
private Func < IGqlpObjField , MapPair < string > > FieldMember ( GeneratorContext context )
@@ -14,5 +19,30 @@ private Func<IGqlpObjAlternate, MapPair<string>> AlternateMember(GeneratorContex
14
19
=> alternate => new ( "As" + alternate . Name , TypeString ( alternate , context ) ) ;
15
20
16
21
protected virtual string TypeString ( IGqlpObjType type , GeneratorContext context )
17
- => context . GetTypeAst < IGqlpType > ( type . FullType ) ? . Name ?? type . FullType ;
22
+ => context . GetTypeAst < IGqlpType > ( type . Name ) ? . Name
23
+ ?? ( type . IsTypeParam ? "T" : "" ) + type . Name ;
24
+
25
+ protected override void TypeHeader ( TObj ast , GeneratorContext context )
26
+ {
27
+ string typeParams = ast . TypeParams . Select ( p => "T" + p . Name ) . Surround ( "<" , ">" , "," ) ;
28
+
29
+ context . AppendLine ( $ "public interface I{ ast . Name } { typeParams } ") ;
30
+ if ( ast . Parent is not null ) {
31
+ context . AppendLine ( " : I" + ast . Parent . Name ) ;
32
+ }
33
+ }
34
+
35
+ protected override void ClassHeader ( TObj ast , GeneratorContext context )
36
+ {
37
+ string typeParams = ast . TypeParams . Select ( p => "T" + p . Name ) . Surround ( "<" , ">" , "," ) ;
38
+
39
+ context . AppendLine ( $ "public class { TypePrefix } { ast . Name } { typeParams } ") ;
40
+
41
+ if ( ast . Parent is not null ) {
42
+ context . AppendLine ( " : " + TypePrefix + ast . Parent . Name ) ;
43
+ context . AppendLine ( " , I" + ast . Name + typeParams ) ;
44
+ } else {
45
+ context . AppendLine ( " : I" + ast . Name + typeParams ) ;
46
+ }
47
+ }
18
48
}
0 commit comments