4
4
using System . Text . Json . Serialization ;
5
5
using System . Text . Json . Serialization . Metadata ;
6
6
using Catglobe . CgScript . Common ;
7
+ using Microsoft . Extensions . Logging ;
7
8
using Microsoft . Extensions . Options ;
8
9
9
10
namespace Catglobe . CgScript . Runtime ;
10
11
11
- internal partial class DevelopmentModeCgScriptApiClient ( HttpClient httpClient , IScriptProvider scriptProvider , IOptions < CgScriptOptions > options ) : ApiClientBase ( httpClient )
12
+ internal partial class DevelopmentModeCgScriptApiClient ( HttpClient httpClient , IScriptProvider scriptProvider , IOptions < CgScriptOptions > options , ILogger < ICgScriptApiClient > logger ) : ApiClientBase ( httpClient , logger )
12
13
{
13
14
private IReadOnlyDictionary < string , IScriptDefinition > ? _scriptDefinitions ;
14
15
private BaseCgScriptMaker ? _cgScriptMaker ;
@@ -26,12 +27,9 @@ protected override async ValueTask<string> GetPath(string scriptName, string? ad
26
27
JsonContent . Create ( new DynamicCgScript < TP > ( scriptName , await GetScript ( scriptName ) , parameter , callJsonTypeInfo ) , mediaType : null , jsonTypeInfo : DynamicCgScriptSerializer . Default . IDynamicScript ) ;
27
28
28
29
[ RequiresUnreferencedCode ( "JSON" ) ]
29
- protected override async Task < JsonContent ? > GetJsonContent < TP > ( string scriptName , TP ? parameter , JsonSerializerOptions ? callJsonTypeInfo ) where TP : default
30
- {
31
- var script = await GetScript ( scriptName ) ;
32
-
33
- throw new NotImplementedException ( ) ;
34
- }
30
+ protected override async Task < JsonContent ? > GetJsonContent < TP > ( string scriptName , TP ? parameter , JsonSerializerOptions ? jsonOptions ) where TP : default =>
31
+ JsonContent . Create ( new DynamicCgScriptUnreferenced < TP > ( scriptName , await GetScript ( scriptName ) , parameter , jsonOptions ) , mediaType : null ,
32
+ jsonTypeInfo : DynamicCgScriptSerializer . Default . IDynamicScript ) ;
35
33
36
34
private Task < string > GetScript ( string scriptName ) => _cgScriptMaker ! . GetContent ( scriptName ) ;
37
35
@@ -44,15 +42,28 @@ internal interface IDynamicScript
44
42
}
45
43
46
44
[ JsonConverter ( typeof ( DynamicConverter ) ) ]
47
- internal record DynamicCgScript < T > ( string ScriptName , string Script , T ? Parameter , JsonTypeInfo < T > jsonTypeInfo ) : IDynamicScript
45
+ internal record DynamicCgScript < T > ( string ScriptName , string Script , T ? Parameter , JsonTypeInfo < T > JsonTypeInfo ) : IDynamicScript
46
+ {
47
+ public void WriteParameter ( Utf8JsonWriter writer )
48
+ {
49
+ writer . WritePropertyName ( "parameter" ) ;
50
+ if ( Parameter is null )
51
+ writer . WriteNullValue ( ) ;
52
+ else
53
+ JsonSerializer . Serialize ( writer , Parameter , JsonTypeInfo ) ;
54
+ }
55
+ }
56
+ [ JsonConverter ( typeof ( DynamicConverter ) ) ]
57
+ [ RequiresUnreferencedCode ( "JSON" ) ]
58
+ internal record DynamicCgScriptUnreferenced < T > ( string ScriptName , string Script , T ? Parameter , JsonSerializerOptions ? Options ) : IDynamicScript
48
59
{
49
60
public void WriteParameter ( Utf8JsonWriter writer )
50
61
{
51
62
writer . WritePropertyName ( "parameter" ) ;
52
63
if ( Parameter is null )
53
64
writer . WriteNullValue ( ) ;
54
65
else
55
- JsonSerializer . Serialize ( writer , Parameter , jsonTypeInfo ) ;
66
+ JsonSerializer . Serialize ( writer , Parameter , Parameter . GetType ( ) , Options ) ;
56
67
}
57
68
}
58
69
0 commit comments