88using System . Text . Json ;
99using System . Text . Json . Serialization ;
1010using System . Text . Json . Serialization . Metadata ;
11- using Microsoft . AspNetCore . Components ;
1211using Microsoft . AspNetCore . Components . RenderTree ;
13- using Microsoft . AspNetCore . Components . Web ;
14-
15- [ assembly: JsonSerializable ( typeof ( WebEventDescriptor ) ) ]
16- [ assembly: JsonSerializable ( typeof ( EventArgs ) ) ]
17- [ assembly: JsonSerializable ( typeof ( ChangeEventArgs ) ) ]
18- [ assembly: JsonSerializable ( typeof ( ClipboardEventArgs ) ) ]
19- [ assembly: JsonSerializable ( typeof ( DragEventArgs ) ) ]
20- [ assembly: JsonSerializable ( typeof ( ErrorEventArgs ) ) ]
21- [ assembly: JsonSerializable ( typeof ( FocusEventArgs ) ) ]
22- [ assembly: JsonSerializable ( typeof ( KeyboardEventArgs ) ) ]
23- [ assembly: JsonSerializable ( typeof ( MouseEventArgs ) ) ]
24- [ assembly: JsonSerializable ( typeof ( PointerEventArgs ) ) ]
25- [ assembly: JsonSerializable ( typeof ( ProgressEventArgs ) ) ]
26- [ assembly: JsonSerializable ( typeof ( TouchEventArgs ) ) ]
27- [ assembly: JsonSerializable ( typeof ( WheelEventArgs ) ) ]
2812
2913namespace Microsoft . AspNetCore . Components . Web
3014{
@@ -34,7 +18,7 @@ internal class WebEventData
3418 // once the event ID (and possibly the type of the eventArgs) becomes known.
3519 public static WebEventData Parse (
3620 Renderer renderer ,
37- IWebEventJsonSerializerContext jsonSerializerContext ,
21+ WebEventJsonContext jsonSerializerContext ,
3822 string eventDescriptorJson ,
3923 string eventArgsJson )
4024 {
@@ -57,7 +41,7 @@ public static WebEventData Parse(
5741
5842 public static WebEventData Parse (
5943 Renderer renderer ,
60- IWebEventJsonSerializerContext jsonSerializerContext ,
44+ WebEventJsonContext jsonSerializerContext ,
6145 WebEventDescriptor eventDescriptor ,
6246 string eventArgsJson )
6347 {
@@ -87,7 +71,7 @@ private WebEventData(int browserRendererId, ulong eventHandlerId, EventFieldInfo
8771
8872 private static EventArgs ParseEventArgsJson (
8973 Renderer renderer ,
90- IWebEventJsonSerializerContext jsonSerializerContext ,
74+ WebEventJsonContext jsonSerializerContext ,
9175 ulong eventHandlerId ,
9276 string eventName ,
9377 string eventArgsJson )
@@ -112,7 +96,7 @@ private static EventArgs ParseEventArgsJson(
11296 private static bool TryDeserializeStandardWebEventArgs (
11397 string eventName ,
11498 string eventArgsJson ,
115- IWebEventJsonSerializerContext jsonSerializerContext ,
99+ WebEventJsonContext jsonSerializerContext ,
116100 [ NotNullWhen ( true ) ] out EventArgs ? eventArgs )
117101 {
118102 // For back-compatibility, we recognize the built-in list of web event names and hard-code
@@ -252,7 +236,7 @@ private static bool TryDeserializeStandardWebEventArgs(
252236
253237 static T Deserialize < T > ( string json , JsonTypeInfo < T ? > jsonTypeInfo ) => JsonSerializer . Deserialize ( json , jsonTypeInfo ) ! ;
254238
255- private static ChangeEventArgs DeserializeChangeEventArgs ( string eventArgsJson , IWebEventJsonSerializerContext jsonSerializerContext )
239+ private static ChangeEventArgs DeserializeChangeEventArgs ( string eventArgsJson , WebEventJsonContext jsonSerializerContext )
256240 {
257241 var changeArgs = Deserialize ( eventArgsJson , jsonSerializerContext . ChangeEventArgs ) ;
258242 var jsonElement = ( JsonElement ) changeArgs . Value ! ;
@@ -273,28 +257,23 @@ private static ChangeEventArgs DeserializeChangeEventArgs(string eventArgsJson,
273257 }
274258 return changeArgs ;
275259 }
260+ }
276261
277- #nullable disable
278- // WebView has different nullability settings compared to Server and WebAssembly
279- // which weirds out JSON's nullability for these types. Disable nullability for this contract
280- // until we can update everything to haave uniform nullability.
281- internal interface IWebEventJsonSerializerContext
282- {
283- JsonSerializerOptions Options { get ; }
284-
285- JsonTypeInfo < ChangeEventArgs > ChangeEventArgs { get ; }
286- JsonTypeInfo < WebEventDescriptor > WebEventDescriptor { get ; }
287- JsonTypeInfo < ClipboardEventArgs > ClipboardEventArgs { get ; }
288- JsonTypeInfo < DragEventArgs > DragEventArgs { get ; }
289- JsonTypeInfo < FocusEventArgs > FocusEventArgs { get ; }
290- JsonTypeInfo < KeyboardEventArgs > KeyboardEventArgs { get ; }
291- JsonTypeInfo < MouseEventArgs > MouseEventArgs { get ; }
292- JsonTypeInfo < ErrorEventArgs > ErrorEventArgs { get ; }
293- JsonTypeInfo < ProgressEventArgs > ProgressEventArgs { get ; }
294- JsonTypeInfo < TouchEventArgs > TouchEventArgs { get ; }
295- JsonTypeInfo < PointerEventArgs > PointerEventArgs { get ; }
296- JsonTypeInfo < WheelEventArgs > WheelEventArgs { get ; }
297- JsonTypeInfo < EventArgs > EventArgs { get ; }
298- }
262+ [ JsonSerializable ( typeof ( WebEventDescriptor ) , GenerationMode = JsonSourceGenerationMode . Serialization ) ]
263+ [ JsonSerializable ( typeof ( WebEventDescriptor ) , GenerationMode = JsonSourceGenerationMode . Serialization ) ]
264+ [ JsonSerializable ( typeof ( EventArgs ) , GenerationMode = JsonSourceGenerationMode . Serialization ) ]
265+ [ JsonSerializable ( typeof ( ChangeEventArgs ) , GenerationMode = JsonSourceGenerationMode . Serialization ) ]
266+ [ JsonSerializable ( typeof ( ClipboardEventArgs ) , GenerationMode = JsonSourceGenerationMode . Serialization ) ]
267+ [ JsonSerializable ( typeof ( DragEventArgs ) , GenerationMode = JsonSourceGenerationMode . Serialization ) ]
268+ [ JsonSerializable ( typeof ( ErrorEventArgs ) , GenerationMode = JsonSourceGenerationMode . Serialization ) ]
269+ [ JsonSerializable ( typeof ( FocusEventArgs ) , GenerationMode = JsonSourceGenerationMode . Serialization ) ]
270+ [ JsonSerializable ( typeof ( KeyboardEventArgs ) , GenerationMode = JsonSourceGenerationMode . Serialization ) ]
271+ [ JsonSerializable ( typeof ( MouseEventArgs ) , GenerationMode = JsonSourceGenerationMode . Serialization ) ]
272+ [ JsonSerializable ( typeof ( PointerEventArgs ) , GenerationMode = JsonSourceGenerationMode . Serialization ) ]
273+ [ JsonSerializable ( typeof ( ProgressEventArgs ) , GenerationMode = JsonSourceGenerationMode . Serialization ) ]
274+ [ JsonSerializable ( typeof ( TouchEventArgs ) , GenerationMode = JsonSourceGenerationMode . Serialization ) ]
275+ [ JsonSerializable ( typeof ( WheelEventArgs ) , GenerationMode = JsonSourceGenerationMode . Serialization ) ]
276+ internal sealed partial class WebEventJsonContext : JsonSerializerContext
277+ {
299278 }
300279}
0 commit comments