Skip to content

Commit 0bcf3c6

Browse files
author
Michael Ganss
committed
Remove beta label
1 parent 7e5b04a commit 0bcf3c6

File tree

5 files changed

+75
-1
lines changed

5 files changed

+75
-1
lines changed

XmlSchemaClassGenerator.Tests/XmlTests.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ private static IEnumerable<string> ConvertXml(string name, string xsd, Generator
111111
const string EppPattern = "xsd/epp/*.xsd";
112112
const string GraphMLPattern = "xsd/graphml/ygraphml.xsd";
113113
const string UnionPattern = "xsd/union/union.xsd";
114+
const string GuidPattern = "xsd/guid/*.xsd";
114115
const string NullableReferenceAttributesPattern = "xsd/nullablereferenceattributes/nullablereference.xsd";
115116

116117
// IATA test takes too long to perform every time
@@ -156,6 +157,40 @@ public void TestClient()
156157
SharedTestFunctions.TestSamples(Output, "Client", ClientPattern);
157158
}
158159

160+
[Fact, TestPriority(1)]
161+
[UseCulture("en-US")]
162+
public void TestGuid()
163+
{
164+
var assembly = Compiler.Generate("Guid", GuidPattern);
165+
var testType = assembly.GetType("Guid.Test");
166+
var idProperty = testType.GetProperty("Id");
167+
var elementIdProperty = testType.GetProperty("ElementId");
168+
169+
Assert.Equal(typeof(Nullable<>).MakeGenericType(typeof(Guid)), idProperty.PropertyType);
170+
Assert.Equal(typeof(Guid), elementIdProperty.PropertyType);
171+
172+
var serializer = new XmlSerializer(testType);
173+
174+
var test = Activator.CreateInstance(testType);
175+
var idGuid = Guid.NewGuid();
176+
var elementGuid = Guid.NewGuid();
177+
178+
idProperty.SetValue(test, idGuid);
179+
elementIdProperty.SetValue(test, elementGuid);
180+
181+
var sw = new StringWriter();
182+
183+
serializer.Serialize(sw, test);
184+
185+
var xml = sw.ToString();
186+
var sr = new StringReader(xml);
187+
188+
var o = serializer.Deserialize(sr);
189+
190+
Assert.Equal(idGuid, idProperty.GetValue(o));
191+
Assert.Equal(elementGuid, elementIdProperty.GetValue(o));
192+
}
193+
159194
[Fact, TestPriority(1)]
160195
[UseCulture("en-US")]
161196
public void TestUnion()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
3+
targetNamespace="http://microsoft.com/wsdl/types/">
4+
<xs:simpleType name="guid">
5+
<xs:annotation>
6+
<xs:documentation xml:lang="en">
7+
The representation of a GUID, generally the id of an element.
8+
</xs:documentation>
9+
</xs:annotation>
10+
<xs:restriction base="xs:string">
11+
<xs:pattern value="[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}"/>
12+
</xs:restriction>
13+
</xs:simpleType>
14+
</xs:schema>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd"
3+
elementFormDefault="qualified"
4+
xmlns="http://tempuri.org/XMLSchema.xsd"
5+
xmlns:mstns="http://tempuri.org/XMLSchema.xsd"
6+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
7+
xmlns:s="http://microsoft.com/wsdl/types/"
8+
>
9+
<xs:import namespace="http://microsoft.com/wsdl/types/" schemaLocation="guid.xsd"></xs:import>
10+
<xs:element name="Test">
11+
<xs:complexType>
12+
<xs:sequence>
13+
<xs:element name="ElementId" type="s:guid"></xs:element>
14+
</xs:sequence>
15+
<xs:attribute name="Id" type="s:guid"></xs:attribute>
16+
</xs:complexType>
17+
</xs:element>
18+
</xs:schema>

XmlSchemaClassGenerator/CodeUtilities.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ private static Type GetIntegerDerivedType(XmlSchemaDatatype xml, GeneratorConfig
9999
Type FromFallback() => configuration.UseIntegerDataTypeAsFallback && configuration.IntegerDataType != null ? configuration.IntegerDataType : typeof(string);
100100
}
101101

102+
private static readonly XmlQualifiedName GuidQualifiedName = new("guid", "http://microsoft.com/wsdl/types/");
103+
102104
public static Type GetEffectiveType(this XmlSchemaDatatype type, GeneratorConfiguration configuration, IEnumerable<RestrictionModel> restrictions, XmlSchemaType schemaType, bool attribute = false)
103105
{
104106
var resultType = type.TypeCode switch
@@ -112,6 +114,11 @@ public static Type GetEffectiveType(this XmlSchemaDatatype type, GeneratorConfig
112114
_ => type.ValueType,
113115
};
114116

117+
if (schemaType.QualifiedName == GuidQualifiedName)
118+
{
119+
resultType = typeof(Guid);
120+
}
121+
115122
if (type.Variety == XmlSchemaDatatypeVariety.List)
116123
{
117124
if (resultType.IsArray)

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 2.0.{build}-beta
1+
version: 2.0.{build}
22
skip_tags: true
33
image: Visual Studio 2022
44
environment:

0 commit comments

Comments
 (0)