-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathClassTemplate.tt
More file actions
74 lines (67 loc) · 2.25 KB
/
ClassTemplate.tt
File metadata and controls
74 lines (67 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<#@ template language="C#" #>
<#@ assembly name="System.Core" #>
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Linq2GraphQL.Client;
using Linq2GraphQL.Client.Common;
namespace <#= namespaceName #>;
<# if (NullableEnabled()) { #>
#pragma warning disable CS8618
<# } #>
<# if (classType.AllFields.Any(e => e.IsMethod)) { #>
public static class <#= classType.Name #>Extensions
{
<# foreach (var field in classType.AllFields.Where(e => e.IsMethod)) { #>
[GraphQLMember("<#= field.Name #>")]
<# if (field.IsDeprecated) { #>
[Obsolete("<#= field.DeprecationReason #>")]
<# } #>
public static <#= GetFieldCSharpName(field) #> <#= field.CSharpName #>(this <#= classType.Name #> <#= classType.Name.ToCamelCase() #>, <#= field.GetArgString(true) #>)
{
return <#= classType.Name.ToCamelCase() #>.GetMethodValue<<#= GetFieldCSharpName(field) #>>("<#= field.Name #>", <#= field.GetArgNames() #>);
}
<# } #>
}
<#
}
#>
<# if (classType.HasDescription) {#>
/// <summary>
/// <#= classType.SummaryDescription #>
/// </summary>
<#
}
#>
public partial class <#= classType.Name #> <#= classType.GetInterfacesString("GraphQLTypeBase") #>
{
<# foreach (var field in classType.AllFields) { #>
<# if (field.IsMethod) { #>
private LazyProperty<<#= GetFieldCSharpName(field) #>> _<#= field.Name #> = new();
/// <summary>
/// Do not use in Query, only to retrive result
/// </summary>
<# if (field.IsDeprecated) { #>
[Obsolete("<#= field.DeprecationReason #>")]
<# } #>
public <#= GetFieldCSharpName(field) #> <#= field.CSharpName #> => _<#= field.Name #>.Value(() => GetFirstMethodValue<<#= GetFieldCSharpName(field) #>>("<#= field.Name #>"));
<# } else { #>
<# if (field.HasDescription) { #>
/// <summary>
/// <#= field.SummaryDescription #>
/// </summary>
<# } #>
<# if (field.IsDeprecated) { #>
[Obsolete("<#= field.DeprecationReason #>")]
<# } #>
[GraphQLMember("<#= field.Name #>")]
[JsonPropertyName("<#= field.Name #>")]
public <#= GetFieldCSharpName(field) #> <#= field.CSharpName #> { get; set; }
<# } #>
<# } #>
<# if (classType.HasInterfaces) { #>
[GraphQLMember("__typename")]
[JsonPropertyName("__typename")]
public string __TypeName { get; set; }
<# } #>
}