Skip to content

Commit

Permalink
Add support for fixed values (fixes #16)
Browse files Browse the repository at this point in the history
Create models for global types before those for global elements (fixes #17)
  • Loading branch information
Michael Ganss committed Sep 22, 2016
1 parent a68f700 commit 7b0ce51
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion XmlSchemaClassGenerator.Tests/xsd/client/client.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<xs:complexType name="MandatoryStringType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute fixed="True" name="MandatoryField" type="xs:string" use="optional" />
<xs:attribute fixed="True" name="MandatoryField" type="xs:string" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Expand Down
18 changes: 9 additions & 9 deletions XmlSchemaClassGenerator/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,13 @@ private void BuildModel()
AttributeGroups = Set.Schemas().Cast<XmlSchema>().SelectMany(s => s.AttributeGroups.Values.Cast<XmlSchemaAttributeGroup>()).ToDictionary(g => g.QualifiedName);
Groups = Set.Schemas().Cast<XmlSchema>().SelectMany(s => s.Groups.Values.Cast<XmlSchemaGroup>()).ToDictionary(g => g.QualifiedName);

foreach (var globalType in Set.GlobalTypes.Values.Cast<XmlSchemaType>())
{
var schema = globalType.GetSchema();
var source = (schema == null ? null : new Uri(schema.SourceUri));
var type = CreateTypeModel(source, globalType, globalType.QualifiedName);
}

foreach (var rootElement in Set.GlobalElements.Values.Cast<XmlSchemaElement>())
{
var source = new Uri(rootElement.GetSchema().SourceUri);
Expand Down Expand Up @@ -388,13 +395,6 @@ private void BuildModel()
type.RootElementName = rootElement.QualifiedName;
}
}

foreach (var globalType in Set.GlobalTypes.Values.Cast<XmlSchemaType>())
{
var schema = globalType.GetSchema();
var source = (schema == null ? null : new Uri(schema.SourceUri));
var type = CreateTypeModel(source, globalType, globalType.QualifiedName);
}
}

// see http://msdn.microsoft.com/en-us/library/z2w0sxhf.aspx
Expand Down Expand Up @@ -707,7 +707,7 @@ private IEnumerable<PropertyModel> CreatePropertiesForAttributes(Uri source, Typ
Type = CreateTypeModel(source, attribute.AttributeSchemaType, attributeQualifiedName),
IsAttribute = true,
IsNullable = attribute.Use != XmlSchemaUse.Required,
DefaultValue = attribute.DefaultValue,
DefaultValue = attribute.DefaultValue ?? (attribute.Use != XmlSchemaUse.Optional ? attribute.FixedValue : null),
Form = attribute.Form == XmlSchemaForm.None ? attribute.GetSchema().AttributeFormDefault : attribute.Form,
XmlNamespace = attribute.QualifiedName.Namespace != "" && attribute.QualifiedName.Namespace != typeModel.XmlSchemaName.Namespace ? attribute.QualifiedName.Namespace : null,
};
Expand Down Expand Up @@ -779,7 +779,7 @@ private IEnumerable<PropertyModel> CreatePropertiesForElements(Uri source, TypeM
IsNillable = element.IsNillable,
IsNullable = item.MinOccurs < 1.0m,
IsCollection = item.MaxOccurs > 1.0m || particle.MaxOccurs > 1.0m, // http://msdn.microsoft.com/en-us/library/vstudio/d3hx2s7e(v=vs.100).aspx
DefaultValue = element.DefaultValue,
DefaultValue = element.DefaultValue ?? (item.MinOccurs >= 1.0m ? element.FixedValue : null),
Form = element.Form == XmlSchemaForm.None ? element.GetSchema().ElementFormDefault : element.Form,
XmlNamespace = element.QualifiedName.Namespace != "" && element.QualifiedName.Namespace != typeModel.XmlSchemaName.Namespace ? element.QualifiedName.Namespace : null,
};
Expand Down

0 comments on commit 7b0ce51

Please sign in to comment.