@@ -14,17 +14,14 @@ public static string GenerateCalls(InterfaceData @interface)
1414namespace { @interface . Namespace }
1515{{
1616{ @interface . Methods . Select ( static method => $@ "
17- public class { method . Name } Args
18- {{
19- { string . Join ( "\n " , method . Parameters . Properties . Select ( static x => $@ "public { x . Type } { ( x . IsNullable ? "?" : "" ) } { x . Name . ToPropertyName ( ) } {{ get; set; }}{ ( ! string . IsNullOrEmpty ( x . DefaultValue ) ? $ " = { x . DefaultValue } ;" : "" ) } ") ) }
20- }}
17+ public class { method . Name } Args
18+ {{
19+ { string . Join ( "\n " , method . Parameters . Properties . Select ( static x => $@ "public { x . Type } { ( x . IsNullable ? "?" : "" ) } { x . Name . ToPropertyName ( ) } {{ get; set; }}{ ( ! string . IsNullOrEmpty ( x . DefaultValue ) ? $ " = { x . DefaultValue } ;" : "" ) } ") ) }
20+ }}
2121" ) . Inject ( ) }
2222
2323 public static partial class { extensionsClassName }
2424 {{
25-
26-
27-
2825 public static global::System.Collections.Generic.IReadOnlyDictionary<string, global::System.Func<string, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task<string>>> AsCalls(this { @interface . Name } service)
2926 {{
3027 return new global::System.Collections.Generic.Dictionary<string, global::System.Func<string, global::System.Threading.CancellationToken, global::System.Threading.Tasks.Task<string>>>
@@ -68,20 +65,19 @@ public static partial class {extensionsClassName}
6865 #if NET6_0_OR_GREATER
6966 if(global::System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault)
7067 {{
71- return
72- global::System.Text.Json.JsonSerializer.Deserialize<{ method . Name } Args>(json, new global::System.Text.Json.JsonSerializerOptions
68+ #pragma disable warning IL2026, IL3050
69+ return global::System.Text.Json.JsonSerializer.Deserialize<{ method . Name } Args>(json, new global::System.Text.Json.JsonSerializerOptions
7370 {{
7471 PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase,
7572 Converters = {{{{ new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }}}}
7673 }}) ??
7774 throw new global::System.InvalidOperationException(""Could not deserialize JSON."");
78-
75+ #pragma restore warning IL2026, IL3050
7976 }}
8077 else
8178 {{
8279 return global::System.Text.Json.JsonSerializer.Deserialize(json, global::{ @interface . Namespace } .{ extensionsClassName } JsonSerializerContext.Default.{ method . Name } Args) ??
83- throw new global::System.InvalidOperationException(""Could not deserialize JSON."");
84-
80+ throw new global::System.InvalidOperationException(""Could not deserialize JSON."");
8581 }}
8682 #else
8783 return
@@ -104,11 +100,13 @@ public static partial class {extensionsClassName}
104100 #if NET6_0_OR_GREATER
105101 if(global::System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault)
106102 {{
107- return global::System.Text.Json.JsonSerializer.Serialize(jsonResult, new global::System.Text.Json.JsonSerializerOptions
103+ #pragma disable warning IL2026, IL3050
104+ return global::System.Text.Json.JsonSerializer.Serialize(jsonResult, new global::System.Text.Json.JsonSerializerOptions
108105 {{
109106 PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase,
110107 Converters = {{ new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }},
111108 }});
109+ #pragma restore warning IL2026, IL3050
112110 }}
113111 else
114112 {{
@@ -120,11 +118,9 @@ public static partial class {extensionsClassName}
120118 PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase,
121119 Converters = {{ new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }},
122120 }});
123- #endif
124-
121+ #endif
125122 }}
126123" ) . Inject ( ) }
127-
128124{ @interface . Methods . Where ( static x => x is { IsAsync : false , IsVoid : true } ) . Select ( method => $@ "
129125 public static void Call{ method . Name } (this { @interface . Name } functions, string json)
130126 {{
@@ -146,11 +142,13 @@ public static partial class {extensionsClassName}
146142 #if NET6_0_OR_GREATER
147143 if(global::System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault)
148144 {{
149- return global::System.Text.Json.JsonSerializer.Serialize(jsonResult, new global::System.Text.Json.JsonSerializerOptions
145+ #pragma disable warning IL2026, IL3050
146+ return global::System.Text.Json.JsonSerializer.Serialize(jsonResult, new global::System.Text.Json.JsonSerializerOptions
150147 {{
151148 PropertyNamingPolicy = global::System.Text.Json.JsonNamingPolicy.CamelCase,
152149 Converters = {{ new global::System.Text.Json.Serialization.JsonStringEnumConverter(global::System.Text.Json.JsonNamingPolicy.CamelCase) }},
153150 }});
151+ #pragma restore warning IL2026, IL3050
154152 }}
155153 else
156154 {{
@@ -194,12 +192,10 @@ public static partial class {extensionsClassName}
194192 }}
195193 }}
196194
197- public partial class { extensionsClassName } JsonSerializerContext: global::System.Text.Json.Serialization.JsonSerializerContext
198- {{
199-
200- }}
195+ public partial class { extensionsClassName } JsonSerializerContext: global::System.Text.Json.Serialization.JsonSerializerContext
196+ {{
197+ }}
201198}}" ;
202-
203199 return res ;
204200 }
205201}
0 commit comments