1- using System ;
1+ #nullable enable
2+ using System ;
23using System . Collections . Generic ;
34using System . IO ;
45using System . Linq ;
@@ -61,6 +62,11 @@ private static void TraverseAllSimpleTypes(XmlSchemaObject schemaObject, ref Dic
6162
6263 bool didAdd = true ;
6364 switch ( schemaObject ) {
65+ case XmlSchemaAttribute attribute : {
66+ didAdd = simpleTypes . AddIfNotAlreadyExists ( attribute , attribute . AttributeSchemaType ) ;
67+ break ;
68+ }
69+
6470 case XmlSchemaElement element : {
6571 if ( element . ElementSchemaType is XmlSchemaSimpleType simpleType ) {
6672 didAdd = simpleTypes . AddIfNotAlreadyExists ( element , simpleType ) ;
@@ -92,12 +98,7 @@ private static void TraverseAllSimpleTypes(XmlSchemaObject schemaObject, ref Dic
9298 break ;
9399 }
94100
95- case XmlSchemaAttribute attribute : {
96- didAdd = simpleTypes . AddIfNotAlreadyExists ( attribute , attribute . AttributeSchemaType ) ;
97- break ;
98- }
99-
100- case XmlSchemaComplexType complexType :
101+ case XmlSchemaComplexType complexType : {
101102 foreach ( var attribute in complexType . AttributeUses . Values . OfType < XmlSchemaAttribute > ( ) ) {
102103 if ( attribute . AttributeSchemaType is { } simpleType ) {
103104 didAdd = simpleTypes . AddIfNotAlreadyExists ( attribute , simpleType ) ;
@@ -110,20 +111,42 @@ private static void TraverseAllSimpleTypes(XmlSchemaObject schemaObject, ref Dic
110111 }
111112
112113 break ;
114+ }
115+
116+ case XmlSchemaGroupBase groupBase : {
117+ OneOf < XmlSchemaAll , XmlSchemaSequence , XmlSchemaChoice > matchModel = default ;
118+ if ( groupBase is XmlSchemaAll all ) { matchModel = all ; }
119+ else if ( groupBase is XmlSchemaSequence seq ) { matchModel = seq ; }
120+ else if ( groupBase is XmlSchemaChoice choice ) { matchModel = choice ; }
113121
114- case XmlSchemaGroupBase groupBase when groupBase is XmlSchemaAll all :
115- foreach ( var item in all . Items ) {
122+ foreach ( var item in matchModel . Match ( a => a . Items , s => s . Items , c => c . Items ) ) {
116123 TraverseAllSimpleTypes ( item , ref simpleTypes , out breakOutOfLoop ) ;
117124 if ( breakOutOfLoop ) return ;
118125 }
119126
120127 break ;
121-
128+ }
122129 }
123130
124131 breakOutOfLoop = ! didAdd ;
125132 }
126133
134+ public static bool IsOfAnonymousType ( this XmlSchemaAttribute attr )
135+ {
136+ return attr . SchemaType != null && ! (
137+ ( attr . AttributeSchemaType ? . IsGlobal ( ) ) . GetValueOrDefault ( ) &&
138+ ( attr . AttributeSchemaType ? . IsBuiltInSimpleType ( ) ) . GetValueOrDefault ( )
139+ ) ;
140+ }
141+
142+ public static bool IsOfAnonymousType ( this XmlSchemaElement el )
143+ {
144+ return el . SchemaType != null && ! (
145+ ( el . ElementSchemaType ? . IsGlobal ( ) ) . GetValueOrDefault ( ) &&
146+ ( el . ElementSchemaType ? . IsBuiltInSimpleType ( ) ) . GetValueOrDefault ( )
147+ ) ;
148+ }
149+
127150 /// <summary>
128151 /// Returns true or false if the current <paramref name="attribute"/> defines an inline enumeration of values.
129152 /// </summary>
0 commit comments