@@ -50,6 +50,42 @@ public PropertyNode this[string key]
5050 }
5151 }
5252
53+ public override Dictionary < string , T > CreateMap < T > ( Func < string , string > keySelector , Func < MapNode , string , T > map )
54+ {
55+ var jsonMap = this . node ;
56+ if ( jsonMap == null )
57+ {
58+ throw new AsyncApiReaderException ( $ "Expected map while parsing { typeof ( T ) . Name } ", this . Context ) ;
59+ }
60+
61+ var nodes = jsonMap . Select (
62+ n =>
63+ {
64+ var originalKey = n . Key ;
65+ var newKey = keySelector ( originalKey ) ;
66+ T value ;
67+ try
68+ {
69+ this . Context . StartObject ( originalKey ) ;
70+ value = n . Value is JsonObject
71+ ? map ( new MapNode ( this . Context , n . Value ) , originalKey )
72+ : default ( T ) ;
73+ }
74+ finally
75+ {
76+ this . Context . EndObject ( ) ;
77+ }
78+
79+ return new
80+ {
81+ key = newKey ,
82+ value ,
83+ } ;
84+ } ) ;
85+
86+ return nodes . ToDictionary ( k => k . key , v => v . value ) ;
87+ }
88+
5389 public override Dictionary < string , T > CreateMap < T > ( Func < MapNode , T > map )
5490 {
5591 var jsonMap = this . node ;
@@ -207,14 +243,23 @@ public override AsyncApiAny CreateAny()
207243 return new AsyncApiAny ( this . node ) ;
208244 }
209245
210- public void ParseFields < T > ( ref T parentInstance , IDictionary < string , Action < T , ParseNode > > fixedFields , IDictionary < Func < string , bool > , Action < T , string , ParseNode > > patternFields )
246+ public void ParseFields < T > ( T parentInstance , IDictionary < string , Action < T , ParseNode > > fixedFields , IDictionary < Func < string , bool > , Action < T , string , ParseNode > > patternFields )
211247 {
212248 foreach ( var propertyNode in this )
213249 {
214250 propertyNode . ParseField ( parentInstance , fixedFields , patternFields ) ;
215251 }
216252 }
217253
254+ // Parse only patternfields on top.
255+ public void ParseFields < T > ( T parentInstance , IDictionary < Func < string , bool > , Action < T , string , ParseNode > > patternFields )
256+ {
257+ foreach ( var propertyNode in this )
258+ {
259+ propertyNode . ParseField ( parentInstance , patternFields ) ;
260+ }
261+ }
262+
218263 private string ToScalarValue ( JsonNode node )
219264 {
220265 var scalarNode = node is JsonValue value ? value : throw new AsyncApiException ( $ "Expected scalar value") ;
0 commit comments