Skip to content

Commit 44a77db

Browse files
committed
Addded setting for DateAsString for config optiopns
1 parent ca0d164 commit 44a77db

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/TypeScriptBuilder/TypeScriptBuilder.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/TypeScriptBuilder/TypeScriptGenerator.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ public string TypeName(Type type, bool forceClass = false)
7979
case TypeCode.String:
8080
return "string";
8181
case TypeCode.DateTime:
82-
return "string"; //TODO: Might be a setting in the future? Changed from Date -> string since dates serialized as json would be a string.
82+
83+
if (_options.DatesAsString)
84+
return "string";
85+
86+
return "Date";
8387
case TypeCode.Object:
8488
if (type.IsArray)
8589
return TypeName(type.GetElementType()) + "[]";

src/TypeScriptBuilder/TypeScriptGeneratorOptions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,11 @@ public class TypeScriptGeneratorOptions
2020
/// Creates models without any namespaces.
2121
/// </summary>
2222
public bool IgnoreNamespaces = false; // ignores namespace in emissions
23+
24+
/// <summary>
25+
/// Use this to have dates typed as string. Useful since JSON-serialization of C# DateTime will be a string.
26+
/// </summary>
27+
public bool DatesAsString = false;
28+
2329
}
2430
}

0 commit comments

Comments
 (0)