@@ -461,6 +461,29 @@ public virtual string CreateETag(ResourceContext resourceContext)
461461 return null ;
462462 }
463463
464+ /// <summary>
465+ /// Creates the <see cref="ODataNestedResourceInfo"/> to be written while writing this delta nested property (complex or entity).
466+ /// </summary>
467+ /// <param name="property">The property for which the nested resource info is being created.</param>
468+ /// <param name="resourceContext">The context for the property instance being written.</param>
469+ /// <returns>The nested resource info to be written. Returns 'null' will omit this property serialization.</returns>
470+ /// <remarks>It enables customer to get more control by overriding this method. </remarks>
471+ public virtual ODataNestedResourceInfo CreateDeltaNestedResourceInfo ( IEdmProperty property , ResourceContext resourceContext )
472+ {
473+ if ( property == null )
474+ {
475+ throw Error . ArgumentNull ( nameof ( property ) ) ;
476+ }
477+
478+ return property . Type != null ?
479+ new ODataNestedResourceInfo
480+ {
481+ IsCollection = property . Type . IsCollection ( ) ,
482+ Name = property . Name
483+ } :
484+ null ;
485+ }
486+
464487 /// <summary>
465488 /// Creates the <see cref="ODataNestedResourceInfo"/> to be written while writing this dynamic complex property.
466489 /// </summary>
@@ -705,15 +728,14 @@ internal void WriteDeltaComplexProperties(SelectExpandNode selectExpandNode,
705728
706729 foreach ( KeyValuePair < IEdmStructuralProperty , PathSelectItem > complexProperty in complexProperties )
707730 {
708- ODataNestedResourceInfo nestedResourceInfo = new ODataNestedResourceInfo
709- {
710- IsCollection = complexProperty . Key . Type . IsCollection ( ) ,
711- Name = complexProperty . Key . Name
712- } ;
731+ ODataNestedResourceInfo nestedResourceInfo = CreateDeltaNestedResourceInfo ( complexProperty . Key , resourceContext ) ;
713732
714- writer . WriteStart ( nestedResourceInfo ) ;
715- WriteDeltaComplexAndExpandedNavigationProperty ( complexProperty . Key , null , resourceContext , writer ) ;
716- writer . WriteEnd ( ) ;
733+ if ( nestedResourceInfo != null )
734+ {
735+ writer . WriteStart ( nestedResourceInfo ) ;
736+ WriteDeltaComplexAndExpandedNavigationProperty ( complexProperty . Key , null , resourceContext , writer ) ;
737+ writer . WriteEnd ( ) ;
738+ }
717739 }
718740 }
719741
@@ -732,15 +754,14 @@ internal void WriteDeltaNavigationProperties(SelectExpandNode selectExpandNode,
732754
733755 foreach ( KeyValuePair < IEdmNavigationProperty , Type > navigationProperty in navigationProperties )
734756 {
735- ODataNestedResourceInfo nestedResourceInfo = new ODataNestedResourceInfo
736- {
737- IsCollection = navigationProperty . Key . Type . IsCollection ( ) ,
738- Name = navigationProperty . Key . Name
739- } ;
757+ ODataNestedResourceInfo nestedResourceInfo = CreateDeltaNestedResourceInfo ( navigationProperty . Key , resourceContext ) ;
740758
741- writer . WriteStart ( nestedResourceInfo ) ;
742- WriteDeltaComplexAndExpandedNavigationProperty ( navigationProperty . Key , null , resourceContext , writer , navigationProperty . Value ) ;
743- writer . WriteEnd ( ) ;
759+ if ( nestedResourceInfo != null )
760+ {
761+ writer . WriteStart ( nestedResourceInfo ) ;
762+ WriteDeltaComplexAndExpandedNavigationProperty ( navigationProperty . Key , null , resourceContext , writer , navigationProperty . Value ) ;
763+ writer . WriteEnd ( ) ;
764+ }
744765 }
745766 }
746767
@@ -760,15 +781,14 @@ internal async Task WriteDeltaNavigationPropertiesAsync(SelectExpandNode selectE
760781
761782 foreach ( KeyValuePair < IEdmNavigationProperty , Type > navigationProperty in navigationProperties )
762783 {
763- ODataNestedResourceInfo nestedResourceInfo = new ODataNestedResourceInfo
764- {
765- IsCollection = navigationProperty . Key . Type . IsCollection ( ) ,
766- Name = navigationProperty . Key . Name
767- } ;
784+ ODataNestedResourceInfo nestedResourceInfo = CreateDeltaNestedResourceInfo ( navigationProperty . Key , resourceContext ) ;
768785
769- await writer . WriteStartAsync ( nestedResourceInfo ) ;
770- await WriteDeltaComplexAndExpandedNavigationPropertyAsync ( navigationProperty . Key , null , resourceContext , writer , navigationProperty . Value ) ;
771- await writer . WriteEndAsync ( ) ;
786+ if ( nestedResourceInfo != null )
787+ {
788+ await writer . WriteStartAsync ( nestedResourceInfo ) ;
789+ await WriteDeltaComplexAndExpandedNavigationPropertyAsync ( navigationProperty . Key , null , resourceContext , writer , navigationProperty . Value ) ;
790+ await writer . WriteEndAsync ( ) ;
791+ }
772792 }
773793 }
774794
@@ -793,15 +813,14 @@ internal async Task WriteDeltaComplexPropertiesAsync(SelectExpandNode selectExpa
793813
794814 foreach ( KeyValuePair < IEdmStructuralProperty , PathSelectItem > complexProperty in complexProperties )
795815 {
796- ODataNestedResourceInfo nestedResourceInfo = new ODataNestedResourceInfo
797- {
798- IsCollection = complexProperty . Key . Type . IsCollection ( ) ,
799- Name = complexProperty . Key . Name
800- } ;
816+ ODataNestedResourceInfo nestedResourceInfo = CreateDeltaNestedResourceInfo ( complexProperty . Key , resourceContext ) ;
801817
802- await writer . WriteStartAsync ( nestedResourceInfo ) ;
803- await WriteDeltaComplexAndExpandedNavigationPropertyAsync ( complexProperty . Key , null , resourceContext , writer ) ;
804- await writer . WriteEndAsync ( ) ;
818+ if ( nestedResourceInfo != null )
819+ {
820+ await writer . WriteStartAsync ( nestedResourceInfo ) ;
821+ await WriteDeltaComplexAndExpandedNavigationPropertyAsync ( complexProperty . Key , null , resourceContext , writer ) ;
822+ await writer . WriteEndAsync ( ) ;
823+ }
805824 }
806825 }
807826
0 commit comments