@@ -48,7 +48,7 @@ public ModelBuilder(GeneratorConfiguration configuration, XmlSchemaSet set)
4848 {
4949 var schema = globalType . GetSchema ( ) ;
5050 var source = string . IsNullOrEmpty ( schema ? . SourceUri ) ? null : new Uri ( schema . SourceUri ) ;
51- var type = CreateTypeModel ( source , globalType , globalType . QualifiedName ) ;
51+ CreateTypeModel ( source , globalType , globalType . QualifiedName ) ;
5252 }
5353
5454 foreach ( var rootElement in set . GlobalElements . Values . Cast < XmlSchemaElement > ( ) )
@@ -60,7 +60,7 @@ public ModelBuilder(GeneratorConfiguration configuration, XmlSchemaSet set)
6060
6161 if ( type . RootElementName != null )
6262 {
63- if ( type is ClassModel )
63+ if ( type is ClassModel classModel )
6464 {
6565 // There is already another global element with this type.
6666 // Need to create an empty derived class.
@@ -81,7 +81,7 @@ public ModelBuilder(GeneratorConfiguration configuration, XmlSchemaSet set)
8181
8282 Types [ rootElement . QualifiedName ] = derivedClassModel ;
8383
84- derivedClassModel . BaseClass = ( ClassModel ) type ;
84+ derivedClassModel . BaseClass = classModel ;
8585 ( ( ClassModel ) derivedClassModel . BaseClass ) . DerivedTypes . Add ( derivedClassModel ) ;
8686
8787 derivedClassModel . RootElementName = rootElement . QualifiedName ;
@@ -131,10 +131,10 @@ private TypeModel CreateTypeModel(Uri source, XmlSchemaAnnotated type, XmlQualif
131131 }
132132 else if ( type is XmlSchemaSimpleType simpleType )
133133 {
134- return CreateTypeModel ( source , simpleType , namespaceModel , qualifiedName , docs ) ;
134+ return CreateTypeModel ( simpleType , namespaceModel , qualifiedName , docs ) ;
135135 }
136136
137- throw new Exception ( $ "Cannot build declaration for { qualifiedName } ") ;
137+ throw new NotSupportedException ( $ "Cannot build declaration for { qualifiedName } ") ;
138138 }
139139
140140 private TypeModel CreateTypeModel ( Uri source , XmlSchemaGroup group , NamespaceModel namespaceModel , XmlQualifiedName qualifiedName , List < DocumentationModel > docs )
@@ -225,21 +225,19 @@ private TypeModel CreateTypeModel(Uri source, XmlSchemaComplexType complexType,
225225 {
226226 var baseModel = CreateTypeModel ( source , complexType . BaseXmlSchemaType , complexType . BaseXmlSchemaType . QualifiedName ) ;
227227 classModel . BaseClass = baseModel ;
228- if ( baseModel is ClassModel ) { ( ( ClassModel ) classModel . BaseClass ) . DerivedTypes . Add ( classModel ) ; }
228+ if ( baseModel is ClassModel baseClassModel ) { baseClassModel . DerivedTypes . Add ( classModel ) ; }
229229 }
230230
231231 XmlSchemaParticle particle = null ;
232232 if ( classModel . BaseClass != null )
233233 {
234- if ( complexType . ContentModel . Content is XmlSchemaComplexContentExtension )
234+ if ( complexType . ContentModel . Content is XmlSchemaComplexContentExtension complexContent )
235235 {
236- particle = ( ( XmlSchemaComplexContentExtension ) complexType . ContentModel . Content ) . Particle ;
236+ particle = complexContent . Particle ;
237237 }
238238
239239 // If it's a restriction, do not duplicate elements on the derived class, they're already in the base class.
240240 // See https://msdn.microsoft.com/en-us/library/f3z3wh0y.aspx
241- //else if (complexType.ContentModel.Content is XmlSchemaComplexContentRestriction)
242- // particle = ((XmlSchemaComplexContentRestriction)complexType.ContentModel.Content).Particle;
243241 }
244242 else particle = complexType . ContentTypeParticle ;
245243
@@ -257,21 +255,17 @@ private TypeModel CreateTypeModel(Uri source, XmlSchemaComplexType complexType,
257255 XmlSchemaObjectCollection attributes = null ;
258256 if ( classModel . BaseClass != null )
259257 {
260- if ( complexType . ContentModel . Content is XmlSchemaComplexContentExtension )
258+ if ( complexType . ContentModel . Content is XmlSchemaComplexContentExtension complexContent )
261259 {
262- attributes = ( ( XmlSchemaComplexContentExtension ) complexType . ContentModel . Content ) . Attributes ;
260+ attributes = complexContent . Attributes ;
263261 }
264- else if ( complexType . ContentModel . Content is XmlSchemaSimpleContentExtension )
262+ else if ( complexType . ContentModel . Content is XmlSchemaSimpleContentExtension simpleContent )
265263 {
266- attributes = ( ( XmlSchemaSimpleContentExtension ) complexType . ContentModel . Content ) . Attributes ;
264+ attributes = simpleContent . Attributes ;
267265 }
268266
269267 // If it's a restriction, do not duplicate attributes on the derived class, they're already in the base class.
270268 // See https://msdn.microsoft.com/en-us/library/f3z3wh0y.aspx
271- //else if (complexType.ContentModel.Content is XmlSchemaComplexContentRestriction)
272- // attributes = ((XmlSchemaComplexContentRestriction)complexType.ContentModel.Content).Attributes;
273- //else if (complexType.ContentModel.Content is XmlSchemaSimpleContentRestriction)
274- // attributes = ((XmlSchemaSimpleContentRestriction)complexType.ContentModel.Content).Attributes;
275269 }
276270 else { attributes = complexType . Attributes ; }
277271
@@ -309,7 +303,7 @@ private TypeModel CreateTypeModel(Uri source, XmlSchemaComplexType complexType,
309303 return classModel ;
310304 }
311305
312- private TypeModel CreateTypeModel ( Uri source , XmlSchemaSimpleType simpleType , NamespaceModel namespaceModel , XmlQualifiedName qualifiedName , List < DocumentationModel > docs )
306+ private TypeModel CreateTypeModel ( XmlSchemaSimpleType simpleType , NamespaceModel namespaceModel , XmlQualifiedName qualifiedName , List < DocumentationModel > docs )
313307 {
314308 var restrictions = new List < RestrictionModel > ( ) ;
315309
@@ -714,7 +708,7 @@ private string BuildNamespace(Uri source, string xmlNamespace)
714708 return result ;
715709 }
716710
717- throw new Exception ( string . Format ( "Namespace {0} not provided through map or generator." , xmlNamespace ) ) ;
711+ throw new ArgumentException ( string . Format ( "Namespace {0} not provided through map or generator." , xmlNamespace ) ) ;
718712 }
719713
720714 private string ToTitleCase ( string s )
0 commit comments