Skip to content

Commit

Permalink
Find DataType in simple type's ancestors (fixes #18)
Browse files Browse the repository at this point in the history
  • Loading branch information
mganss committed Dec 4, 2016
1 parent 7b0ce51 commit 6d73b02
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions XmlSchemaClassGenerator/TypeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -912,11 +912,19 @@ private IEnumerable<CodeAttributeDeclaration> GetAttributes(bool isArray)
var simpleModel = Type as SimpleModel;
if (simpleModel != null && simpleModel.UseDataTypeAttribute)
{
var name = Type.XmlSchemaType.GetQualifiedName();
if (name.Namespace == XmlSchema.Namespace)
// walk up the inheritance chain to find DataType if the simple type is derived (see #18)
var xmlSchemaType = Type.XmlSchemaType;
while (xmlSchemaType != null)
{
var dataType = new CodeAttributeArgument("DataType", new CodePrimitiveExpression(name.Name));
attribute.Arguments.Add(dataType);
var name = xmlSchemaType.GetQualifiedName();
if (name.Namespace == XmlSchema.Namespace && name.Name != "anySimpleType")
{
var dataType = new CodeAttributeArgument("DataType", new CodePrimitiveExpression(name.Name));
attribute.Arguments.Add(dataType);
break;
}
else
xmlSchemaType = xmlSchemaType.BaseXmlSchemaType;
}
}
}
Expand Down

0 comments on commit 6d73b02

Please sign in to comment.