33
44using  System ; 
55using  System . Collections . Generic ; 
6+ using  System . Diagnostics . CodeAnalysis ; 
67using  System . Diagnostics . Contracts ; 
78using  System . Text . Json ; 
89using  System . Text . Json . Serialization ; 
@@ -23,13 +24,15 @@ public partial class ContractDescriptorParser
2324    /// <summary> 
2425    ///  Parses the "compact" representation of a contract descriptor. 
2526    /// </summary> 
27+     // Workaround for https://github.com/dotnet/runtime/issues/101205 
28+     [ DynamicDependency ( DynamicallyAccessedMemberTypes . All ,  typeof ( Root ) ) ] 
2629    public  static   ContractDescriptor ?  ParseCompact ( ReadOnlySpan < byte >  json ) 
2730    { 
2831        return  JsonSerializer . Deserialize ( json ,  ContractDescriptorContext . Default . ContractDescriptor ) ; 
2932    } 
3033
3134    [ JsonSerializable ( typeof ( ContractDescriptor ) ) ] 
32-     [ JsonSerializable ( typeof ( int ) ) ] 
35+     [ JsonSerializable ( typeof ( int ? ) ) ] 
3336    [ JsonSerializable ( typeof ( string ) ) ] 
3437    [ JsonSerializable ( typeof ( Dictionary < string ,  int > ) ) ] 
3538    [ JsonSerializable ( typeof ( Dictionary < string ,  TypeDescriptor > ) ) ] 
@@ -38,11 +41,17 @@ public partial class ContractDescriptorParser
3841    [ JsonSerializable ( typeof ( TypeDescriptor ) ) ] 
3942    [ JsonSerializable ( typeof ( FieldDescriptor ) ) ] 
4043    [ JsonSerializable ( typeof ( GlobalDescriptor ) ) ] 
44+     [ JsonSerializable ( typeof ( Dictionary < string ,  JsonElement > ) ) ] 
4145    [ JsonSourceGenerationOptions ( AllowTrailingCommas  =  true , 
4246                                DictionaryKeyPolicy  =  JsonKnownNamingPolicy . Unspecified ,  // contracts, types and globals are case sensitive 
4347                                PropertyNamingPolicy  =  JsonKnownNamingPolicy . CamelCase , 
4448                                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 ) ] ) ] 
4655    internal  sealed  partial  class  ContractDescriptorContext  :  JsonSerializerContext 
4756    { 
4857    } 
@@ -58,7 +67,13 @@ public class ContractDescriptor
5867        public  Dictionary < string ,  GlobalDescriptor > ?  Globals  {  get ;  set ;  } 
5968
6069        [ 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+ 
6277    } 
6378
6479    [ JsonConverter ( typeof ( TypeDescriptorConverter ) ) ] 
0 commit comments