From 6d73b02a0a434d5ca1d89f6ea4f8983296983238 Mon Sep 17 00:00:00 2001 From: Michael Ganss Date: Sun, 4 Dec 2016 20:23:31 +0100 Subject: [PATCH] Find DataType in simple type's ancestors (fixes #18) --- XmlSchemaClassGenerator/TypeModel.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/XmlSchemaClassGenerator/TypeModel.cs b/XmlSchemaClassGenerator/TypeModel.cs index 12bb39be..aec85e04 100644 --- a/XmlSchemaClassGenerator/TypeModel.cs +++ b/XmlSchemaClassGenerator/TypeModel.cs @@ -912,11 +912,19 @@ private IEnumerable 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; } } }