diff --git a/XmlSchemaClassGenerator.Tests/XmlTests.cs b/XmlSchemaClassGenerator.Tests/XmlTests.cs index 8256882c..ba89f441 100644 --- a/XmlSchemaClassGenerator.Tests/XmlTests.cs +++ b/XmlSchemaClassGenerator.Tests/XmlTests.cs @@ -111,6 +111,7 @@ private static IEnumerable ConvertXml(string name, string xsd, Generator const string EppPattern = "xsd/epp/*.xsd"; const string GraphMLPattern = "xsd/graphml/ygraphml.xsd"; const string UnionPattern = "xsd/union/union.xsd"; + const string GuidPattern = "xsd/guid/*.xsd"; const string NullableReferenceAttributesPattern = "xsd/nullablereferenceattributes/nullablereference.xsd"; // IATA test takes too long to perform every time @@ -156,6 +157,40 @@ public void TestClient() SharedTestFunctions.TestSamples(Output, "Client", ClientPattern); } + [Fact, TestPriority(1)] + [UseCulture("en-US")] + public void TestGuid() + { + var assembly = Compiler.Generate("Guid", GuidPattern); + var testType = assembly.GetType("Guid.Test"); + var idProperty = testType.GetProperty("Id"); + var elementIdProperty = testType.GetProperty("ElementId"); + + Assert.Equal(typeof(Nullable<>).MakeGenericType(typeof(Guid)), idProperty.PropertyType); + Assert.Equal(typeof(Guid), elementIdProperty.PropertyType); + + var serializer = new XmlSerializer(testType); + + var test = Activator.CreateInstance(testType); + var idGuid = Guid.NewGuid(); + var elementGuid = Guid.NewGuid(); + + idProperty.SetValue(test, idGuid); + elementIdProperty.SetValue(test, elementGuid); + + var sw = new StringWriter(); + + serializer.Serialize(sw, test); + + var xml = sw.ToString(); + var sr = new StringReader(xml); + + var o = serializer.Deserialize(sr); + + Assert.Equal(idGuid, idProperty.GetValue(o)); + Assert.Equal(elementGuid, elementIdProperty.GetValue(o)); + } + [Fact, TestPriority(1)] [UseCulture("en-US")] public void TestUnion() diff --git a/XmlSchemaClassGenerator.Tests/xsd/guid/guid.xsd b/XmlSchemaClassGenerator.Tests/xsd/guid/guid.xsd new file mode 100644 index 00000000..67cf6789 --- /dev/null +++ b/XmlSchemaClassGenerator.Tests/xsd/guid/guid.xsd @@ -0,0 +1,14 @@ + + + + + + The representation of a GUID, generally the id of an element. + + + + + + + \ No newline at end of file diff --git a/XmlSchemaClassGenerator.Tests/xsd/guid/guidtest.xsd b/XmlSchemaClassGenerator.Tests/xsd/guid/guidtest.xsd new file mode 100644 index 00000000..89792733 --- /dev/null +++ b/XmlSchemaClassGenerator.Tests/xsd/guid/guidtest.xsd @@ -0,0 +1,18 @@ + + + + + + + + + + + + diff --git a/XmlSchemaClassGenerator/CodeUtilities.cs b/XmlSchemaClassGenerator/CodeUtilities.cs index 9e0b79c2..949131c8 100644 --- a/XmlSchemaClassGenerator/CodeUtilities.cs +++ b/XmlSchemaClassGenerator/CodeUtilities.cs @@ -99,6 +99,8 @@ private static Type GetIntegerDerivedType(XmlSchemaDatatype xml, GeneratorConfig Type FromFallback() => configuration.UseIntegerDataTypeAsFallback && configuration.IntegerDataType != null ? configuration.IntegerDataType : typeof(string); } + private static readonly XmlQualifiedName GuidQualifiedName = new("guid", "http://microsoft.com/wsdl/types/"); + public static Type GetEffectiveType(this XmlSchemaDatatype type, GeneratorConfiguration configuration, IEnumerable restrictions, XmlSchemaType schemaType, bool attribute = false) { var resultType = type.TypeCode switch @@ -112,6 +114,11 @@ public static Type GetEffectiveType(this XmlSchemaDatatype type, GeneratorConfig _ => type.ValueType, }; + if (schemaType.QualifiedName == GuidQualifiedName) + { + resultType = typeof(Guid); + } + if (type.Variety == XmlSchemaDatatypeVariety.List) { if (resultType.IsArray) diff --git a/appveyor.yml b/appveyor.yml index 2dd18e66..53f454e8 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 2.0.{build}-beta +version: 2.0.{build} skip_tags: true image: Visual Studio 2022 environment: