@@ -382,6 +382,8 @@ let rec private transformType
382
382
| GlueMember.IndexSignature _ -> false
383
383
| GlueMember.MethodSignature _
384
384
| GlueMember.Property _
385
+ | GlueMember.GetAccessor _
386
+ | GlueMember.SetAccessor _
385
387
| GlueMember.CallSignature _
386
388
| GlueMember.Method _
387
389
| GlueMember.ConstructSignature _ -> true
@@ -827,6 +829,61 @@ module private TransformMembers =
827
829
: FSharpMember list
828
830
=
829
831
members
832
+ // We want to transform GetAccessor / SetAccessor
833
+ // into a single Property if they are related to the same property
834
+ |> List.choose (
835
+ function
836
+ | GlueMember.GetAccessor getAccessorInfo as self ->
837
+ let associatedSetAccessor =
838
+ members
839
+ |> List.tryFind (
840
+ function
841
+ | GlueMember.SetAccessor setPropertyInfo ->
842
+ getAccessorInfo.Name = setPropertyInfo.Name
843
+ | _ -> false
844
+ )
845
+
846
+ match associatedSetAccessor with
847
+ // If we found an associated SetAccessor, we want to transform into a Property
848
+ // and it is now a read-write property
849
+ | Some _ ->
850
+ {
851
+ Name = getAccessorInfo.Name
852
+ Documentation = getAccessorInfo.Documentation
853
+ Type = getAccessorInfo.Type
854
+ IsOptional = false
855
+ IsStatic = getAccessorInfo.IsStatic
856
+ Accessor = GlueAccessor.ReadWrite
857
+ IsPrivate = getAccessorInfo.IsPrivate
858
+ }
859
+ |> GlueMember.Property
860
+ |> Some
861
+ // Otherwise, we keep the GetAccessor as is
862
+ | None -> Some self
863
+
864
+ | GlueMember.SetAccessor setAccessorInfo as self ->
865
+ let associatedGetAccessor =
866
+ members
867
+ |> List.tryFind (
868
+ function
869
+ | GlueMember.GetAccessor getPropertyInfo ->
870
+ setAccessorInfo.Name = getPropertyInfo.Name
871
+ | _ -> false
872
+ )
873
+
874
+ // If we found an associated GetAccessor, we want to remove the SetAccessor
875
+ // the property has been transformed into a Property during the GetAccessor check
876
+ match associatedGetAccessor with
877
+ | Some _ -> None
878
+ // Otherwise, we keep the SetAccessor as is
879
+ | None -> Some self
880
+ | GlueMember.CallSignature _ as self -> Some self
881
+ | GlueMember.Method _ as self -> Some self
882
+ | GlueMember.Property _ as self -> Some self
883
+ | GlueMember.IndexSignature _ as self -> Some self
884
+ | GlueMember.MethodSignature _ as self -> Some self
885
+ | GlueMember.ConstructSignature _ as self -> Some self
886
+ )
830
887
|> List.choose (
831
888
function
832
889
| GlueMember.Method methodInfo ->
@@ -934,6 +991,52 @@ module private TransformMembers =
934
991
|> FSharpMember.Property
935
992
|> Some
936
993
994
+ | GlueMember.GetAccessor getAccessorInfo ->
995
+ let name , context =
996
+ sanitizeNameAndPushScope getAccessorInfo.Name context
997
+
998
+ let xmlDocInfo = transformComment getAccessorInfo.Documentation
999
+
1000
+ {
1001
+ Attributes = [ yield ! xmlDocInfo.ObsoleteAttributes ]
1002
+ Name = name
1003
+ OriginalName = getAccessorInfo.Name
1004
+ Parameters = []
1005
+ Type = transformType context getAccessorInfo.Type
1006
+ TypeParameters = []
1007
+ IsOptional = false
1008
+ IsStatic = getAccessorInfo.IsStatic
1009
+ Accessor = Some FSharpAccessor.ReadOnly
1010
+ Accessibility = FSharpAccessibility.Public
1011
+ XmlDoc = xmlDocInfo.XmlDoc
1012
+ Body = FSharpMemberInfoBody.NativeOnly
1013
+ }
1014
+ |> FSharpMember.Property
1015
+ |> Some
1016
+
1017
+ | GlueMember.SetAccessor setAccessorInfo ->
1018
+ let name , context =
1019
+ sanitizeNameAndPushScope setAccessorInfo.Name context
1020
+
1021
+ let xmlDocInfo = transformComment setAccessorInfo.Documentation
1022
+
1023
+ {
1024
+ Attributes = [ yield ! xmlDocInfo.ObsoleteAttributes ]
1025
+ Name = name
1026
+ OriginalName = setAccessorInfo.Name
1027
+ Parameters = []
1028
+ Type = transformType context setAccessorInfo.ArgumentType
1029
+ TypeParameters = []
1030
+ IsOptional = false
1031
+ IsStatic = setAccessorInfo.IsStatic
1032
+ Accessor = Some FSharpAccessor.WriteOnly
1033
+ Accessibility = FSharpAccessibility.Public
1034
+ XmlDoc = xmlDocInfo.XmlDoc
1035
+ Body = FSharpMemberInfoBody.NativeOnly
1036
+ }
1037
+ |> FSharpMember.Property
1038
+ |> Some
1039
+
937
1040
| GlueMember.IndexSignature indexSignature ->
938
1041
let name , context = sanitizeNameAndPushScope " Item" context
939
1042
@@ -1036,6 +1139,30 @@ module private TransformMembers =
1036
1139
}
1037
1140
: FSharpParameter
1038
1141
1142
+ | GlueMember.GetAccessor getAccessorInfo ->
1143
+ let name , context =
1144
+ sanitizeNameAndPushScope getAccessorInfo.Name context
1145
+
1146
+ {
1147
+ Attributes = []
1148
+ Name = name
1149
+ IsOptional = false
1150
+ Type = transformType context getAccessorInfo.Type
1151
+ }
1152
+ : FSharpParameter
1153
+
1154
+ | GlueMember.SetAccessor setAccessorInfo ->
1155
+ let name , context =
1156
+ sanitizeNameAndPushScope setAccessorInfo.Name context
1157
+
1158
+ {
1159
+ Attributes = []
1160
+ Name = name
1161
+ IsOptional = false
1162
+ Type = transformType context setAccessorInfo.ArgumentType
1163
+ }
1164
+ : FSharpParameter
1165
+
1039
1166
| GlueMember.IndexSignature indexSignature ->
1040
1167
let name , context = sanitizeNameAndPushScope " Item" context
1041
1168
@@ -1206,7 +1333,9 @@ module TypeAliasDeclaration =
1206
1333
match m with
1207
1334
| GlueMember.Method { Name = caseName }
1208
1335
| GlueMember.MethodSignature { Name = caseName }
1209
- | GlueMember.Property { Name = caseName } ->
1336
+ | GlueMember.Property { Name = caseName }
1337
+ | GlueMember.GetAccessor { Name = caseName }
1338
+ | GlueMember.SetAccessor { Name = caseName } ->
1210
1339
1211
1340
let sanitizeResult =
1212
1341
Naming.sanitizeNameWithResult caseName
@@ -1524,6 +1653,8 @@ let private transformTypeAliasDeclaration
1524
1653
match m with
1525
1654
| GlueMember.Method { Type = typ }
1526
1655
| GlueMember.Property { Type = typ }
1656
+ | GlueMember.GetAccessor { Type = typ }
1657
+ | GlueMember.SetAccessor { ArgumentType = typ }
1527
1658
| GlueMember.CallSignature { Type = typ }
1528
1659
| GlueMember.ConstructSignature { Type = typ }
1529
1660
| GlueMember.MethodSignature { Type = typ }
0 commit comments