3
3
4
4
using System ;
5
5
using System . Collections . Generic ;
6
+ using System . Diagnostics . CodeAnalysis ;
6
7
using System . Diagnostics . Contracts ;
7
8
using System . Text . Json ;
8
9
using System . Text . Json . Serialization ;
@@ -23,13 +24,15 @@ public partial class ContractDescriptorParser
23
24
/// <summary>
24
25
/// Parses the "compact" representation of a contract descriptor.
25
26
/// </summary>
27
+ // Workaround for https://github.com/dotnet/runtime/issues/101205
28
+ [ DynamicDependency ( DynamicallyAccessedMemberTypes . All , typeof ( Root ) ) ]
26
29
public static ContractDescriptor ? ParseCompact ( ReadOnlySpan < byte > json )
27
30
{
28
31
return JsonSerializer . Deserialize ( json , ContractDescriptorContext . Default . ContractDescriptor ) ;
29
32
}
30
33
31
34
[ JsonSerializable ( typeof ( ContractDescriptor ) ) ]
32
- [ JsonSerializable ( typeof ( int ) ) ]
35
+ [ JsonSerializable ( typeof ( int ? ) ) ]
33
36
[ JsonSerializable ( typeof ( string ) ) ]
34
37
[ JsonSerializable ( typeof ( Dictionary < string , int > ) ) ]
35
38
[ JsonSerializable ( typeof ( Dictionary < string , TypeDescriptor > ) ) ]
@@ -38,11 +41,17 @@ public partial class ContractDescriptorParser
38
41
[ JsonSerializable ( typeof ( TypeDescriptor ) ) ]
39
42
[ JsonSerializable ( typeof ( FieldDescriptor ) ) ]
40
43
[ JsonSerializable ( typeof ( GlobalDescriptor ) ) ]
44
+ [ JsonSerializable ( typeof ( Dictionary < string , JsonElement > ) ) ]
41
45
[ JsonSourceGenerationOptions ( AllowTrailingCommas = true ,
42
46
DictionaryKeyPolicy = JsonKnownNamingPolicy . Unspecified , // contracts, types and globals are case sensitive
43
47
PropertyNamingPolicy = JsonKnownNamingPolicy . CamelCase ,
44
48
NumberHandling = JsonNumberHandling . AllowReadingFromString ,
45
- ReadCommentHandling = JsonCommentHandling . Skip ) ]
49
+ ReadCommentHandling = JsonCommentHandling . Skip ,
50
+ UnmappedMemberHandling = JsonUnmappedMemberHandling . Skip ,
51
+ UnknownTypeHandling = JsonUnknownTypeHandling . JsonElement ,
52
+ Converters = [ typeof ( TypeDescriptorConverter ) ,
53
+ typeof ( FieldDescriptorConverter ) ,
54
+ typeof ( GlobalDescriptorConverter ) ] ) ]
46
55
internal sealed partial class ContractDescriptorContext : JsonSerializerContext
47
56
{
48
57
}
@@ -58,7 +67,13 @@ public class ContractDescriptor
58
67
public Dictionary < string , GlobalDescriptor > ? Globals { get ; set ; }
59
68
60
69
[ JsonExtensionData ]
61
- public Dictionary < string , object ? > ? Extras { get ; set ; }
70
+ public Dictionary < string , JsonElement > ? Extras { get ; set ; }
71
+
72
+ public override string ToString ( )
73
+ {
74
+ return $ "Version: { Version } , Baseline: { Baseline } , Contracts: { Contracts ? . Count } , Types: { Types ? . Count } , Globals: { Globals ? . Count } ";
75
+ }
76
+
62
77
}
63
78
64
79
[ JsonConverter ( typeof ( TypeDescriptorConverter ) ) ]
0 commit comments