@@ -377,38 +377,10 @@ public Datamodel Decode(string encoding, int encoding_version, string format, in
377377 var id_bits = Reader . ReadBytes ( 16 ) ;
378378 var id = new Guid ( BitConverter . IsLittleEndian ? id_bits : id_bits . Reverse ( ) . ToArray ( ) ) ;
379379
380- Element ? elem = null ;
381- var matchedType = types . TryGetValue ( type , out var classType ) ;
382-
383- if ( matchedType && classType != null && reflectionParams . AttemptReflection )
384- {
385- var isElementDerived = Element . IsElementDerived ( classType ) ;
386- if ( isElementDerived && classType . Name == type )
387- {
388- Type derivedType = classType ;
389-
390- ConstructorInfo ? constructor = typeof ( Element ) . GetConstructor (
391- BindingFlags . Instance | BindingFlags . Public | BindingFlags . NonPublic ,
392- null ,
393- [ typeof ( Datamodel ) , typeof ( string ) , typeof ( Guid ) , typeof ( string ) ] ,
394- null
395- ) ;
396-
397- if ( constructor == null )
398- {
399- throw new InvalidOperationException ( "Failed to get constructor while attemption reflection based deserialisation" ) ;
400- }
401-
402- object uninitializedObject = RuntimeHelpers . GetUninitializedObject ( derivedType ) ;
403- constructor . Invoke ( uninitializedObject , [ dm , name , id , type ] ) ;
404-
405- elem = ( Element ? ) uninitializedObject ;
406- }
407- }
408-
409- if ( elem == null )
380+ if ( ! CodecUtilities . TryConstructCustomElement ( types , dm , type , name , id , out _ ) )
410381 {
411- elem = new Element ( dm , name , id , type ) ;
382+ // note: constructing an element, adds it to the datamodel.AllElements
383+ _ = new Element ( dm , name , id , type ) ;
412384 }
413385 }
414386
@@ -423,7 +395,7 @@ public Datamodel Decode(string encoding, int encoding_version, string format, in
423395 foreach ( var i in Enumerable . Range ( 0 , num_attrs ) )
424396 {
425397 var name = StringDict . ReadString ( Reader ) ;
426- if ( defer_mode == DeferredMode . Automatic && reflectionParams . AttemptReflection == false )
398+ if ( defer_mode == DeferredMode . Automatic )
427399 {
428400 CodecUtilities . AddDeferredAttribute ( elem , name , Reader . BaseStream . Position ) ;
429401 SkipAttribute ( Reader ) ;
0 commit comments