Skip to content

Commit

Permalink
Support duration (fixes #258)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Ganss committed Apr 9, 2021
1 parent 0a67655 commit 61bffc5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion XmlSchemaClassGenerator/CodeUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public static Type GetEffectiveType(this XmlSchemaDatatype type, GeneratorConfig
var resultType = type.TypeCode switch
{
XmlTypeCode.AnyAtomicType => typeof(string),// union
XmlTypeCode.AnyUri or XmlTypeCode.Duration or XmlTypeCode.GDay or XmlTypeCode.GMonth or XmlTypeCode.GMonthDay or XmlTypeCode.GYear or XmlTypeCode.GYearMonth => typeof(string),
XmlTypeCode.AnyUri or XmlTypeCode.GDay or XmlTypeCode.GMonth or XmlTypeCode.GMonthDay or XmlTypeCode.GYear or XmlTypeCode.GYearMonth => typeof(string),
XmlTypeCode.Time => typeof(DateTime),
XmlTypeCode.Idref => typeof(string),
XmlTypeCode.Integer or XmlTypeCode.NegativeInteger or XmlTypeCode.NonNegativeInteger or XmlTypeCode.NonPositiveInteger or XmlTypeCode.PositiveInteger => GetIntegerDerivedType(type, configuration, restrictions),
Expand Down Expand Up @@ -373,6 +373,7 @@ public static KeyValuePair<NamespaceKey, string> ParseNamespace(string nsArg, st
("System.ComponentModel.DataAnnotations", c => c.CompactTypeNames && (c.DataAnnotationMode != DataAnnotationMode.None || c.EntityFramework)),
("System.Diagnostics", c => c.CompactTypeNames && c.GenerateDebuggerStepThroughAttribute),
("System.Linq", c => c.EnableDataBinding),
("System.Xml", c => c.CompactTypeNames),
("System.Xml.Schema", c => c.CompactTypeNames),
("System.Xml.Serialization", c => c.CompactTypeNames)
};
Expand Down
6 changes: 6 additions & 0 deletions XmlSchemaClassGenerator/TypeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,12 @@ public override CodeExpression GetDefaultValueFor(string defaultString, bool att
"Parse", new CodePrimitiveExpression(defaultString));
return rv;
}
else if (type == typeof(TimeSpan))
{
var rv = new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(CodeUtilities.CreateTypeReference(typeof(XmlConvert), Configuration)),
"ToTimeSpan", new CodePrimitiveExpression(defaultString));
return rv;
}
else if (type == typeof(bool) && !string.IsNullOrWhiteSpace(defaultString))
{
if (defaultString == "0")
Expand Down

0 comments on commit 61bffc5

Please sign in to comment.