Skip to content
Merged
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 Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<DebugType>embedded</DebugType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.7.115" PrivateAssets="all" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.8.38-alpha" PrivateAssets="all" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<SourceLinkGitHubHost Include="github.com" ContentUrl="https://raw.githubusercontent.com" />
</ItemGroup>
Expand Down
13 changes: 12 additions & 1 deletion ShapeSifter.Test/Attribute.fs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
namespace ShapeSifter.Test

open System.Reflection
open ShapeSifter

[<RequireQualifiedAccess>]
module Attribute =

/// The F# compiler puts in a bunch of attributes on each of these cases; we're not interested in that.
let filterFromField<'a> (field : TypeField<'a>) =
let filterFromField<'a> (field : TypeField<'a>) : CustomAttributeData list =
field.Attributes
|> List.filter (fun attr ->
[
Expand All @@ -16,3 +17,13 @@ module Attribute =
]
|> List.forall (fun t -> attr.AttributeType <> t)
)

/// Remove built-in runtime attributes like CompilerGeneratedAttribute.
let filterRuntime (attrs : CustomAttributeData list) : System.Type list =
attrs
|> List.choose (fun attr ->
if attr.AttributeType.Module.Name = "System.Private.CoreLib.dll" then
None
else
Some attr.AttributeType
)
15 changes: 8 additions & 7 deletions ShapeSifter.Test/TestUnion.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace ShapeSifter.Test

open System

open System.Reflection
open NUnit.Framework
open FsUnitTyped

Expand All @@ -11,7 +12,7 @@ open ShapeSifter.Patterns
[<TestFixture>]
module TestUnion =

[<AttributeUsage(AttributeTargets.Property, Inherited = true)>]
[<AttributeUsage(AttributeTargets.Method ||| AttributeTargets.Property, Inherited = true)>]
type Foo () =
inherit Attribute ()

Expand Down Expand Up @@ -45,20 +46,20 @@ module TestUnion =

attributes.Count |> shouldEqual 4

attributes.["Case1"] |> shouldBeEmpty
attributes.["Case1"] |> Attribute.filterRuntime |> shouldBeEmpty

attributes.["Case2"]
|> Attribute.filterRuntime
|> List.exactlyOne
|> fun data -> data.AttributeType
|> shouldEqual typeof<Foo>

attributes.["Case3"]
|> Attribute.filterRuntime
|> List.exactlyOne
|> fun data -> data.AttributeType
|> shouldEqual typeof<Bar>

attributes.["Case4"]
|> List.map (fun data -> data.AttributeType)
|> Attribute.filterRuntime
|> List.sortBy (fun ty -> ty.Name)
|> shouldEqual [ typeof<Bar> ; typeof<Foo> ]

Expand Down Expand Up @@ -86,9 +87,9 @@ module TestUnion =
|> Map.ofList

attributes.Count |> shouldEqual 2
attributes.["Field1"] |> shouldBeEmpty
attributes.["Field1"] |> Attribute.filterRuntime |> shouldBeEmpty

attributes.["Field2"]
|> Attribute.filterRuntime
|> List.exactlyOne
|> fun data -> data.AttributeType
|> shouldEqual typeof<Foo>