Skip to content

Commit 51d0fe8

Browse files
committed
Adding a functionmap tool
1 parent 4adc6c3 commit 51d0fe8

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

FsToolkit.ErrorHandling.sln

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FsToolkit.ErrorHandling.Job
1919
EndProject
2020
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FsToolkit.ErrorHandling.JobResult.Tests", "tests\FsToolkit.ErrorHandling.JobResult.Tests\FsToolkit.ErrorHandling.JobResult.Tests.fsproj", "{7DABAB8F-4A02-4992-A3A2-6C550F98C13B}"
2121
EndProject
22+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{9F888E39-5D40-4E29-9529-67C466722431}"
23+
EndProject
24+
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FunctionMap", "tools\FunctionMap\FunctionMap.fsproj", "{600EA6E9-C9F2-4F02-99EF-1F992711DB1C}"
25+
EndProject
2226
Global
2327
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2428
Debug|Any CPU = Debug|Any CPU
@@ -104,6 +108,18 @@ Global
104108
{7DABAB8F-4A02-4992-A3A2-6C550F98C13B}.Release|x64.Build.0 = Release|Any CPU
105109
{7DABAB8F-4A02-4992-A3A2-6C550F98C13B}.Release|x86.ActiveCfg = Release|Any CPU
106110
{7DABAB8F-4A02-4992-A3A2-6C550F98C13B}.Release|x86.Build.0 = Release|Any CPU
111+
{600EA6E9-C9F2-4F02-99EF-1F992711DB1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
112+
{600EA6E9-C9F2-4F02-99EF-1F992711DB1C}.Debug|Any CPU.Build.0 = Debug|Any CPU
113+
{600EA6E9-C9F2-4F02-99EF-1F992711DB1C}.Debug|x64.ActiveCfg = Debug|Any CPU
114+
{600EA6E9-C9F2-4F02-99EF-1F992711DB1C}.Debug|x64.Build.0 = Debug|Any CPU
115+
{600EA6E9-C9F2-4F02-99EF-1F992711DB1C}.Debug|x86.ActiveCfg = Debug|Any CPU
116+
{600EA6E9-C9F2-4F02-99EF-1F992711DB1C}.Debug|x86.Build.0 = Debug|Any CPU
117+
{600EA6E9-C9F2-4F02-99EF-1F992711DB1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
118+
{600EA6E9-C9F2-4F02-99EF-1F992711DB1C}.Release|Any CPU.Build.0 = Release|Any CPU
119+
{600EA6E9-C9F2-4F02-99EF-1F992711DB1C}.Release|x64.ActiveCfg = Release|Any CPU
120+
{600EA6E9-C9F2-4F02-99EF-1F992711DB1C}.Release|x64.Build.0 = Release|Any CPU
121+
{600EA6E9-C9F2-4F02-99EF-1F992711DB1C}.Release|x86.ActiveCfg = Release|Any CPU
122+
{600EA6E9-C9F2-4F02-99EF-1F992711DB1C}.Release|x86.Build.0 = Release|Any CPU
107123
EndGlobalSection
108124
GlobalSection(NestedProjects) = preSolution
109125
{E0466000-F8E4-416B-B605-C65F7602367A} = {E28025A7-EF6A-45BF-8FA0-75E394D3D42B}
@@ -112,5 +128,6 @@ Global
112128
{868CA980-5903-480E-8360-C51F5EC83275} = {D8B86171-2147-49EF-8ADA-1CF8B0A20D40}
113129
{5B1EA296-538E-40E5-BF1D-6CB0F20BB52E} = {E28025A7-EF6A-45BF-8FA0-75E394D3D42B}
114130
{7DABAB8F-4A02-4992-A3A2-6C550F98C13B} = {D8B86171-2147-49EF-8ADA-1CF8B0A20D40}
131+
{600EA6E9-C9F2-4F02-99EF-1F992711DB1C} = {9F888E39-5D40-4E29-9529-67C466722431}
115132
EndGlobalSection
116133
EndGlobal
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net5.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<Compile Include="Program.fs" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="..\..\src\FsToolkit.ErrorHandling\FsToolkit.ErrorHandling.fsproj" />
14+
<ProjectReference Include="..\..\src\FsToolkit.ErrorHandling.TaskResult\FsToolkit.ErrorHandling.TaskResult.fsproj" />
15+
<ProjectReference Include="..\..\src\FsToolkit.ErrorHandling.JobResult\FsToolkit.ErrorHandling.JobResult.fsproj" />
16+
</ItemGroup>
17+
18+
</Project>

tools/FunctionMap/Program.fs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
open System
3+
open System.Reflection
4+
5+
6+
let namesToFilter = [
7+
"GetType"
8+
"ToString"
9+
"Equals"
10+
"GetHashCode"
11+
]
12+
13+
let getMethodsByModuleName moduleName (types : Type seq) =
14+
types
15+
|> Seq.filter(fun t -> t.Name = moduleName)
16+
|> Seq.collect(fun t -> t.GetMethods())
17+
|> Seq.filter(fun m -> namesToFilter |> Seq.contains m.Name |> not )
18+
19+
20+
let report moduleName (methods : MethodInfo seq) =
21+
printfn "---%s---" moduleName
22+
methods
23+
|> Seq.iter(fun m ->
24+
m.Name |> printfn "%s"
25+
)
26+
27+
/// FSharp.Core uses CompiledName attribute to change the case to more C# friendly names,
28+
/// this undoes it
29+
let normalize (name : string) : string =
30+
String(Char.ToLower(name.[0]) |> Array.singleton) + name.Substring(1)
31+
32+
[<EntryPoint>]
33+
let main argv =
34+
let types = [
35+
yield! Assembly.Load("FSharp.Core").GetTypes()
36+
yield! Assembly.Load("FsToolkit.ErrorHandling").GetTypes()
37+
yield! Assembly.Load("FsToolkit.ErrorHandling.TaskResult").GetTypes()
38+
yield! Assembly.Load("FsToolkit.ErrorHandling.JobResult").GetTypes()
39+
]
40+
let getMethodsByModuleName name = getMethodsByModuleName name types
41+
// types |> Seq.iter(fun f -> f.Name |> printfn "%s")
42+
[
43+
"ResultModule" //Fsharp.Core
44+
"OptionModule" //Fsharp.Core
45+
"Option"
46+
"Result"
47+
"Validation"
48+
"Async"
49+
"AsyncResult"
50+
"TaskResult"
51+
"JobResult"
52+
]
53+
|> Seq.collect(fun name -> getMethodsByModuleName name |> Seq.map(fun m -> name, m))
54+
|> Seq.groupBy(fun (name, method) -> normalize method.Name)
55+
|> Seq.sortBy(fst)
56+
|> Seq.iter(fun (method, group) ->
57+
let moduleNames = group |> Seq.map(fst) |> String.concat ","
58+
printfn "%s : %s" method moduleNames
59+
)
60+
61+
62+
0

0 commit comments

Comments
 (0)