Skip to content

Generate custom attributes of enum fields. #28

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Target "AssemblyInfo" (fun _ ->
Attribute.Version release.AssemblyVersion
Attribute.FileVersion release.AssemblyVersion ]

let getProjectDetails projectPath =
let getProjectDetails (projectPath: string) =
let projectName = System.IO.Path.GetFileNameWithoutExtension(projectPath)
( projectPath,
projectName,
Expand Down
1 change: 1 addition & 0 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ group Build
group Test
source https://nuget.org/api/v2

nuget FSharp.Core 4.5.0.0 copy_local: true
nuget NUnit ~> 2
nuget NUnit.Runners ~> 2
471 changes: 465 additions & 6 deletions paket.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/FSharp.Compiler.CodeDom/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ open System.Reflection
[<assembly: AssemblyTitleAttribute("FSharp.Compiler.CodeDom.dll")>]
[<assembly: AssemblyProductAttribute("FSharp.Compiler.CodeDom")>]
[<assembly: AssemblyCompanyAttribute("F# Software Foundation, Microsoft")>]
[<assembly: AssemblyCopyrightAttribute("Copyright © 2004 - 2017 Microsoft")>]
[<assembly: AssemblyCopyrightAttribute("Copyright © 2004 - 2020 Microsoft")>]
[<assembly: AssemblyDescriptionAttribute("A limited CodeDom implementation for F#")>]
[<assembly: AssemblyVersionAttribute("1.0.0.1")>]
[<assembly: AssemblyFileVersionAttribute("1.0.0.1")>]
Expand All @@ -15,7 +15,7 @@ module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "FSharp.Compiler.CodeDom.dll"
let [<Literal>] AssemblyProduct = "FSharp.Compiler.CodeDom"
let [<Literal>] AssemblyCompany = "F# Software Foundation, Microsoft"
let [<Literal>] AssemblyCopyright = "Copyright © 2004 - 2017 Microsoft"
let [<Literal>] AssemblyCopyright = "Copyright © 2004 - 2020 Microsoft"
let [<Literal>] AssemblyDescription = "A limited CodeDom implementation for F#"
let [<Literal>] AssemblyVersion = "1.0.0.1"
let [<Literal>] AssemblyFileVersion = "1.0.0.1"
19 changes: 15 additions & 4 deletions src/FSharp.Compiler.CodeDom/CodeGenerator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1067,15 +1067,19 @@ let generateCustomAttrDecl (c:CodeAttributeDeclaration) =
+> if (c.Arguments.Count = 0) then id else
id -- "(" +> (col sepArgs c.Arguments generateAttributeArg) -- ")"

let generateCustomAttrDeclsList (c:CodeAttributeDeclaration list) target =
let flip f x y = f y x

let generateCustomAttrDeclsList' before after (c:CodeAttributeDeclaration list) target =
let has_target = not (String.IsNullOrEmpty(target))
id
+> if (c = []) then id else
id ++ "[<"
before id "[<"
-- if has_target then target + ": " else ""
+> (colT sepNlnSemiSpace c (fun x -> generateCustomAttrDecl x))
-- ">]"
++ if has_target && target = "assembly" then "do ()" else ""
|> (flip after) (if has_target && target = "assembly" then "do ()" else "")

let generateCustomAttrDeclsList = generateCustomAttrDeclsList' (++) (++)

let generateCustomAttrDeclsForType (c:CodeAttributeDeclaration list) (a:Reflection.TypeAttributes) =
id
Expand Down Expand Up @@ -1127,6 +1131,10 @@ HasSecurity
let generateCustomAttrDecls (c:CodeAttributeDeclarationCollection) =
generateCustomAttrDeclsList (c |> Seq.cast |> Seq.toList)

let generateCustomAttrDeclsForEnumField (c:CodeAttributeDeclarationCollection) =
let after x y = x ++ " " -- y
generateCustomAttrDeclsList' (--) after (c |> Seq.cast |> Seq.toList)

// NOTE: may contain custom attributes - this isn't supported
let generateParamDecl (c:CodeParameterDeclarationExpression) =
let dir = if (c.Direction <> FieldDirection.In) then " byref" else ""
Expand Down Expand Up @@ -1603,7 +1611,10 @@ let generateDelegate (scope:string list) (c:CodeTypeDelegate) =

let generateEnumField (index:int) (c:CodeMemberField) =
id
++ "| " -! c.Name -- " = "
+> col sepNone c.Comments generateStatement
++ "| "
+> generateCustomAttrDeclsForEnumField c.CustomAttributes ""
-! c.Name -- " = "
+> match c.InitExpression with
| null -> str index
| :? CodePrimitiveExpression as p -> generatePrimitiveExpr None p
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<RootNamespace>FSharp.Compiler.CodeDom.Tests</RootNamespace>
<AssemblyName>FSharp.Compiler.CodeDom.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFSharpCoreVersion>4.3.1.0</TargetFSharpCoreVersion>
<Name>FSharp.Compiler.CodeDom.Tests</Name>
<TargetFrameworkProfile />
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
Expand Down Expand Up @@ -62,7 +61,8 @@
</ItemGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="FSharp.Core, Version=$(TargetFSharpCoreVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Reference Include="FSharp.Core, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<HintPath>..\..\packages\test\FSharp.Core\lib\net45\FSharp.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down