66using DocumentFormat . OpenXml . Framework . Metadata ;
77using DocumentFormat . OpenXml . Packaging ;
88using System ;
9+ using System . Collections ;
910using System . Collections . Generic ;
1011using System . Diagnostics ;
1112using System . Diagnostics . CodeAnalysis ;
@@ -67,13 +68,15 @@ public IFeatureCollection Features
6768 {
6869 if ( _features is null )
6970 {
70- _features = new ElementFeatureCollection ( this ) ;
71+ _features = CreateFeatures ( ) ;
7172 }
7273
7374 return _features ;
7475 }
7576 }
7677
78+ private protected virtual IFeatureCollection CreateFeatures ( ) => new ElementFeatureCollection ( this ) ;
79+
7780 private MarkupCompatibilityAttributes ? McAttributesFiled
7881 {
7982 get
@@ -2606,7 +2609,7 @@ internal void RemoveAttributesBasedonMC()
26062609 return root as OpenXmlPartRootElement ;
26072610 }
26082611
2609- private sealed partial class ElementFeatureCollection : IFeatureCollection
2612+ private protected partial class ElementFeatureCollection : IFeatureCollection
26102613 {
26112614 private readonly OpenXmlElement _owner ;
26122615
@@ -2617,15 +2620,27 @@ public ElementFeatureCollection(OpenXmlElement owner)
26172620
26182621 public bool IsReadOnly => true ;
26192622
2620- public int Revision => GetPartFeatures ( ) ? . Revision ?? 0 ;
2623+ public int Revision => GetParentFeatures ( ) ? . Revision ?? 0 ;
2624+
2625+ public virtual IFeatureCollection Default => FeatureCollection . Default ;
26212626
26222627 [ KnownFeature ( typeof ( AnnotationsFeature ) ) ]
26232628 [ KnownFeature ( typeof ( IElementMetadata ) , Factory = nameof ( CreateMetadata ) ) ]
2624- [ DelegatedFeature ( nameof ( GetPartFeatures ) ) ]
2625- [ DelegatedFeature ( nameof ( FeatureCollection . TypedOrDefault ) , typeof ( FeatureCollection ) ) ]
2626- public partial TFeature ? Get < TFeature > ( ) ;
2629+ [ DelegatedFeature ( nameof ( GetParentFeatures ) ) ]
2630+ [ DelegatedFeature ( nameof ( Default ) ) ]
2631+ private partial TFeature ? GetBuiltIn < TFeature > ( ) ;
2632+
2633+ public virtual TFeature ? Get < TFeature > ( ) => GetBuiltIn < TFeature > ( ) ;
2634+
2635+ private IFeatureCollection ? GetParentFeatures ( )
2636+ {
2637+ if ( _owner is OpenXmlPartRootElement root )
2638+ {
2639+ return root . OpenXmlPart ? . Features ;
2640+ }
26272641
2628- public IFeatureCollection ? GetPartFeatures ( ) => _owner . GetPart ( ) ? . Features ;
2642+ return _owner . Parent ? . Features ;
2643+ }
26292644
26302645 private IElementMetadata CreateMetadata ( ) => this . GetRequired < IElementMetadataFactoryFeature > ( ) . GetMetadata ( _owner ) ;
26312646
0 commit comments