Skip to content

Commit fd9254c

Browse files
committed
Add TsType.EnumRef DU case for option set enum references
1 parent fc53e95 commit fd9254c

4 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/Interpretation/InterpretCommon.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let getLink (e: XrmEntity) (a: XrmAttribute) =
1010
| XrmAttributeType.MultiSelectPicklist
1111
| XrmAttributeType.State
1212
| XrmAttributeType.Status ->
13-
let enumName = TsStringUtil.typeToString(a.varType).Split '.' |> Array.last
13+
let enumName = match a.varType with TsType.EnumRef name -> name | _ -> ""
1414
let enum = e.optionSets |> List.tryFind (fun o -> o.name = enumName)
1515

1616
match enum with

src/Interpretation/InterpretEntityMetadata.fs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
module internal DG.XrmTypeScript.InterpretEntityMetadata
22

33
open Utility
4-
open Constants
5-
64
open IntermediateRepresentation
75
open InterpretOptionSetMetadata
86
open Microsoft.Xrm.Sdk.Metadata
@@ -30,10 +28,10 @@ let interpretNormalAttribute aType (options:OptionSet option) =
3028
match aType with
3129
| XrmAttributeType.Money -> TsType.Number, SpecialType.Money
3230

33-
| XrmAttributeType.MultiSelectPicklist -> TsType.Custom $"{ENUM_NS}.{options.Value.name}", SpecialType.MultiSelectOptionSet
31+
| XrmAttributeType.MultiSelectPicklist -> TsType.EnumRef options.Value.name, SpecialType.MultiSelectOptionSet
3432
| XrmAttributeType.Picklist
3533
| XrmAttributeType.State
36-
| XrmAttributeType.Status -> TsType.Custom $"{ENUM_NS}.{options.Value.name}", SpecialType.OptionSet
34+
| XrmAttributeType.Status -> TsType.EnumRef options.Value.name, SpecialType.OptionSet
3735

3836
| XrmAttributeType.Lookup
3937
| XrmAttributeType.PartyList

src/TypeScript/TsStringUtil.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
module internal DG.XrmTypeScript.TsStringUtil
22

3+
open Constants
4+
35
let getConstantType (name:string) = name.Replace("\\", "\\\\").Replace("\"", "\\\"") |> sprintf "\"%s\"" |> TsType.Custom
46

57
let rec wrapIfRecursive ty =
@@ -24,6 +26,7 @@ and typeToString = function
2426
(String.concat ", " (List.collect varToIString v))
2527
(typeToString r)
2628
| TsType.Custom s -> s
29+
| TsType.EnumRef name -> $"{ENUM_NS}.{name}"
2730
| TsType.Generic(n, t) -> sprintf "%s<%s>" n t
2831
| TsType.SpecificGeneric(n,ts)
2932
-> sprintf "%s<%s>" n (ts |> Seq.map typeToString |> String.concat ", ")

src/TypeScript/TypeScript.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type TsType =
2727
| SpecificGeneric of string * TsType list
2828
| Function of Variable list * TsType
2929
| Custom of string
30+
| EnumRef of string
3031
| Union of TsType list
3132
| Intersection of TsType list
3233

0 commit comments

Comments
 (0)