@@ -48,7 +48,7 @@ public ModelBuilder(GeneratorConfiguration configuration, XmlSchemaSet set)
48
48
{
49
49
var schema = globalType . GetSchema ( ) ;
50
50
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 ) ;
52
52
}
53
53
54
54
foreach ( var rootElement in set . GlobalElements . Values . Cast < XmlSchemaElement > ( ) )
@@ -60,7 +60,7 @@ public ModelBuilder(GeneratorConfiguration configuration, XmlSchemaSet set)
60
60
61
61
if ( type . RootElementName != null )
62
62
{
63
- if ( type is ClassModel )
63
+ if ( type is ClassModel classModel )
64
64
{
65
65
// There is already another global element with this type.
66
66
// Need to create an empty derived class.
@@ -81,7 +81,7 @@ public ModelBuilder(GeneratorConfiguration configuration, XmlSchemaSet set)
81
81
82
82
Types [ rootElement . QualifiedName ] = derivedClassModel ;
83
83
84
- derivedClassModel . BaseClass = ( ClassModel ) type ;
84
+ derivedClassModel . BaseClass = classModel ;
85
85
( ( ClassModel ) derivedClassModel . BaseClass ) . DerivedTypes . Add ( derivedClassModel ) ;
86
86
87
87
derivedClassModel . RootElementName = rootElement . QualifiedName ;
@@ -131,10 +131,10 @@ private TypeModel CreateTypeModel(Uri source, XmlSchemaAnnotated type, XmlQualif
131
131
}
132
132
else if ( type is XmlSchemaSimpleType simpleType )
133
133
{
134
- return CreateTypeModel ( source , simpleType , namespaceModel , qualifiedName , docs ) ;
134
+ return CreateTypeModel ( simpleType , namespaceModel , qualifiedName , docs ) ;
135
135
}
136
136
137
- throw new Exception ( $ "Cannot build declaration for { qualifiedName } ") ;
137
+ throw new NotSupportedException ( $ "Cannot build declaration for { qualifiedName } ") ;
138
138
}
139
139
140
140
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,
225
225
{
226
226
var baseModel = CreateTypeModel ( source , complexType . BaseXmlSchemaType , complexType . BaseXmlSchemaType . QualifiedName ) ;
227
227
classModel . BaseClass = baseModel ;
228
- if ( baseModel is ClassModel ) { ( ( ClassModel ) classModel . BaseClass ) . DerivedTypes . Add ( classModel ) ; }
228
+ if ( baseModel is ClassModel baseClassModel ) { baseClassModel . DerivedTypes . Add ( classModel ) ; }
229
229
}
230
230
231
231
XmlSchemaParticle particle = null ;
232
232
if ( classModel . BaseClass != null )
233
233
{
234
- if ( complexType . ContentModel . Content is XmlSchemaComplexContentExtension )
234
+ if ( complexType . ContentModel . Content is XmlSchemaComplexContentExtension complexContent )
235
235
{
236
- particle = ( ( XmlSchemaComplexContentExtension ) complexType . ContentModel . Content ) . Particle ;
236
+ particle = complexContent . Particle ;
237
237
}
238
238
239
239
// If it's a restriction, do not duplicate elements on the derived class, they're already in the base class.
240
240
// 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;
243
241
}
244
242
else particle = complexType . ContentTypeParticle ;
245
243
@@ -257,21 +255,17 @@ private TypeModel CreateTypeModel(Uri source, XmlSchemaComplexType complexType,
257
255
XmlSchemaObjectCollection attributes = null ;
258
256
if ( classModel . BaseClass != null )
259
257
{
260
- if ( complexType . ContentModel . Content is XmlSchemaComplexContentExtension )
258
+ if ( complexType . ContentModel . Content is XmlSchemaComplexContentExtension complexContent )
261
259
{
262
- attributes = ( ( XmlSchemaComplexContentExtension ) complexType . ContentModel . Content ) . Attributes ;
260
+ attributes = complexContent . Attributes ;
263
261
}
264
- else if ( complexType . ContentModel . Content is XmlSchemaSimpleContentExtension )
262
+ else if ( complexType . ContentModel . Content is XmlSchemaSimpleContentExtension simpleContent )
265
263
{
266
- attributes = ( ( XmlSchemaSimpleContentExtension ) complexType . ContentModel . Content ) . Attributes ;
264
+ attributes = simpleContent . Attributes ;
267
265
}
268
266
269
267
// If it's a restriction, do not duplicate attributes on the derived class, they're already in the base class.
270
268
// 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;
275
269
}
276
270
else { attributes = complexType . Attributes ; }
277
271
@@ -309,7 +303,7 @@ private TypeModel CreateTypeModel(Uri source, XmlSchemaComplexType complexType,
309
303
return classModel ;
310
304
}
311
305
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 )
313
307
{
314
308
var restrictions = new List < RestrictionModel > ( ) ;
315
309
@@ -714,7 +708,7 @@ private string BuildNamespace(Uri source, string xmlNamespace)
714
708
return result ;
715
709
}
716
710
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 ) ) ;
718
712
}
719
713
720
714
private string ToTitleCase ( string s )
0 commit comments