diff --git a/XmlSchemaClassGenerator.Tests/XmlTests.cs b/XmlSchemaClassGenerator.Tests/XmlTests.cs index ba89f441..8364e0b1 100644 --- a/XmlSchemaClassGenerator.Tests/XmlTests.cs +++ b/XmlSchemaClassGenerator.Tests/XmlTests.cs @@ -165,9 +165,12 @@ public void TestGuid() var testType = assembly.GetType("Guid.Test"); var idProperty = testType.GetProperty("Id"); var elementIdProperty = testType.GetProperty("ElementId"); + var headerType = assembly.GetType("Guid.V1.Header"); + var referenceProperty = headerType.GetProperty("Reference"); Assert.Equal(typeof(Nullable<>).MakeGenericType(typeof(Guid)), idProperty.PropertyType); Assert.Equal(typeof(Guid), elementIdProperty.PropertyType); + Assert.Equal(typeof(Guid), referenceProperty.PropertyType); var serializer = new XmlSerializer(testType); diff --git a/XmlSchemaClassGenerator.Tests/xsd/guid/header.xsd b/XmlSchemaClassGenerator.Tests/xsd/guid/header.xsd new file mode 100644 index 00000000..877c180c --- /dev/null +++ b/XmlSchemaClassGenerator.Tests/xsd/guid/header.xsd @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/XmlSchemaClassGenerator.Tests/xsd/guid/uuid.xsd b/XmlSchemaClassGenerator.Tests/xsd/guid/uuid.xsd new file mode 100644 index 00000000..9bb156ad --- /dev/null +++ b/XmlSchemaClassGenerator.Tests/xsd/guid/uuid.xsd @@ -0,0 +1,17 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/XmlSchemaClassGenerator/CodeUtilities.cs b/XmlSchemaClassGenerator/CodeUtilities.cs index 949131c8..88b85b7b 100644 --- a/XmlSchemaClassGenerator/CodeUtilities.cs +++ b/XmlSchemaClassGenerator/CodeUtilities.cs @@ -114,7 +114,7 @@ public static Type GetEffectiveType(this XmlSchemaDatatype type, GeneratorConfig _ => type.ValueType, }; - if (schemaType.QualifiedName == GuidQualifiedName) + if (schemaType.IsDerivedFrom(GuidQualifiedName)) { resultType = typeof(Guid); } diff --git a/XmlSchemaClassGenerator/Extensions.cs b/XmlSchemaClassGenerator/Extensions.cs index 056d5476..b693f315 100644 --- a/XmlSchemaClassGenerator/Extensions.cs +++ b/XmlSchemaClassGenerator/Extensions.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Xml; using System.Xml.Schema; namespace XmlSchemaClassGenerator @@ -28,5 +29,16 @@ public static IEnumerable DistinctBy(this IEnumerable !string.IsNullOrEmpty(text) && text.Contains(" ") ? "\"" + text + "\"" : text; + + public static bool IsDerivedFrom(this XmlSchemaType type, XmlQualifiedName qualifiedName) + { + while (type != null) + { + if (type.QualifiedName == qualifiedName) return true; + type = type.BaseXmlSchemaType; + } + + return false; + } } }