Skip to content

Commit 61bffc5

Browse files
author
Michael Ganss
committed
Support duration (fixes #258)
1 parent 0a67655 commit 61bffc5

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

XmlSchemaClassGenerator/CodeUtilities.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public static Type GetEffectiveType(this XmlSchemaDatatype type, GeneratorConfig
177177
var resultType = type.TypeCode switch
178178
{
179179
XmlTypeCode.AnyAtomicType => typeof(string),// union
180-
XmlTypeCode.AnyUri or XmlTypeCode.Duration or XmlTypeCode.GDay or XmlTypeCode.GMonth or XmlTypeCode.GMonthDay or XmlTypeCode.GYear or XmlTypeCode.GYearMonth => typeof(string),
180+
XmlTypeCode.AnyUri or XmlTypeCode.GDay or XmlTypeCode.GMonth or XmlTypeCode.GMonthDay or XmlTypeCode.GYear or XmlTypeCode.GYearMonth => typeof(string),
181181
XmlTypeCode.Time => typeof(DateTime),
182182
XmlTypeCode.Idref => typeof(string),
183183
XmlTypeCode.Integer or XmlTypeCode.NegativeInteger or XmlTypeCode.NonNegativeInteger or XmlTypeCode.NonPositiveInteger or XmlTypeCode.PositiveInteger => GetIntegerDerivedType(type, configuration, restrictions),
@@ -373,6 +373,7 @@ public static KeyValuePair<NamespaceKey, string> ParseNamespace(string nsArg, st
373373
("System.ComponentModel.DataAnnotations", c => c.CompactTypeNames && (c.DataAnnotationMode != DataAnnotationMode.None || c.EntityFramework)),
374374
("System.Diagnostics", c => c.CompactTypeNames && c.GenerateDebuggerStepThroughAttribute),
375375
("System.Linq", c => c.EnableDataBinding),
376+
("System.Xml", c => c.CompactTypeNames),
376377
("System.Xml.Schema", c => c.CompactTypeNames),
377378
("System.Xml.Serialization", c => c.CompactTypeNames)
378379
};

XmlSchemaClassGenerator/TypeModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,12 @@ public override CodeExpression GetDefaultValueFor(string defaultString, bool att
14791479
"Parse", new CodePrimitiveExpression(defaultString));
14801480
return rv;
14811481
}
1482+
else if (type == typeof(TimeSpan))
1483+
{
1484+
var rv = new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(CodeUtilities.CreateTypeReference(typeof(XmlConvert), Configuration)),
1485+
"ToTimeSpan", new CodePrimitiveExpression(defaultString));
1486+
return rv;
1487+
}
14821488
else if (type == typeof(bool) && !string.IsNullOrWhiteSpace(defaultString))
14831489
{
14841490
if (defaultString == "0")

0 commit comments

Comments
 (0)