Skip to content

Commit 435b793

Browse files
committed
add odata support
1 parent 3a1591c commit 435b793

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

Generator.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
public static class Generator
1010
{
11-
public static TypeScriptInterface CreateInterface(string assemblyFile, string rootType)
11+
public static TypeScriptInterface CreateInterface(string assemblyFile, string rootType, bool odata = false)
1212
{
1313
var moduleDefinition = ModuleDefinition.ReadModule(assemblyFile);
1414
if (moduleDefinition == null)
@@ -32,7 +32,7 @@ public static TypeScriptInterface CreateInterface(string assemblyFile, string ro
3232
scriptPropery.Name = propertyDefinition.Name;
3333

3434
var propertyType = propertyDefinition.PropertyType;
35-
scriptPropery.Type = propertyType.ToScriptType();
35+
scriptPropery.Type = propertyType.ToScriptType(odata);
3636
scriptPropery.IsNullable = propertyDefinition.PropertyType.IsNullable();
3737
scriptPropery.IsArray = propertyDefinition.PropertyType.IsScriptArray();
3838
scriptInterface.Properties.Add(scriptPropery);
@@ -184,24 +184,25 @@ public static bool IsDictionary(this TypeReference typeReference, out TypeRefere
184184
return true;
185185
}
186186

187-
public static string ToScriptType(this TypeReference typeReference)
187+
public static string ToScriptType(this TypeReference typeReference, bool odata = false)
188188
{
189189
var t = typeReference.GetUnderlyingType();
190190

191191
switch (t.Name)
192192
{
193193
case "Int16":
194194
case "Int32":
195-
case "Int64":
196195
case "Byte":
197-
case "Decimal":
198196
case "Double":
199197
case "SByte":
200198
case "Single":
201199
case "UInt16":
202200
case "UInt32":
203-
case "UInt64":
204201
return "number";
202+
case "Decimal":
203+
case "Int64":
204+
case "UInt64":
205+
return odata ? "string" : "number";
205206
case "Boolean":
206207
return "boolean";
207208
case "DateTime":

TypeScript.Interface.cst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@
3939
<%@ Property Category="2.Interface" Name="OptionalProperty"
4040
Type="OptionalType" Default="None" Optional="False"
4141
Description="Controls property optional syntax."%>
42+
<%@ Property Category="2.Interface" Name="UseOData"
43+
Type="System.Boolean" Default="False" Optional="False"
44+
Description="Use OData 4 types."%>
4245

43-
<% var scriptInterface = Generator.CreateInterface(AssemblyFile, ClassType); %>
46+
<% var scriptInterface = Generator.CreateInterface(AssemblyFile, ClassType, UseOData); %>
4447
<%= FileHeader ?? string.Empty %>
4548
module <%= ModuleName %> {
4649
"use strict";

0 commit comments

Comments
 (0)