[英]How to use F# records or discriminated unions in PowerShell?
I created a F# project by running these commands:我通过运行以下命令创建了一个 F# 项目:
dotnet new sln -o DotnetCoreProj
cd DotnetCoreProj
dotnet new classlib -lang 'F#' -o src/MyFSModule
dotnet sln add src/MyFSModule/MyFSModule.fsproj
cd src/MyFSModule
@'
namespace MyFSModule
module jwt =
type jwtHeader = {
typ: string
alg: string
}
type hsAlgorithm = HS256 | HS384 | HS512
'@ | Out-File Library.fs -Encoding UTF8
dotnet build
dotnet publish
Import-Module ./bin/Debug/net6.0/publish/MyFSModule.dll
Even though I import the module, I am unable to use the types.即使我导入了模块,我也无法使用这些类型。
PS> $test = [MyFSModule]
InvalidOperation: Unable to find type [MyFSModule].
PS> $test = [MyFSModule]::new()
InvalidOperation: Unable to find type [MyFSModule].
PS> $test = [jwt]
InvalidOperation: Unable to find type [jwt].
PS> $test = [jwt]::new()
InvalidOperation: Unable to find type [jwt].
PS> $test = [MyFSModule+jwt]::new()
InvalidOperation: Unable to find type [MyFSModule+jwt].
PS> $test = [MyFSModule+jwt]
InvalidOperation: Unable to find type [MyFSModule+jwt].
PS> $test = [MyFSModule+hsAlgorithm]
InvalidOperation: Unable to find type [MyFSModule+hsAlgorithm].
PS> $test = [hsAlgorithm]
InvalidOperation: Unable to find type [hsAlgorithm].
PS> $test = [jwt+hsAlgorithm]
InvalidOperation: Unable to find type [jwt+hsAlgorithm].
PS> $fs = [MyFSModule.jwt]
InvalidOperation: Unable to find type [MyFSModule.jwt].
When I run Get-Module -Name MyFSModule
, nothing is exported either.当我运行
Get-Module -Name MyFSModule
时,也没有导出任何内容。
How do I make F# types available in PowerShell?如何使 F# 类型在 PowerShell 中可用?
You were almost right.你几乎是对的。
C:\Projects\psfspoc> [MyFSModule.jwt+jwtHeader]::new("typo","alg")
typ alg
--- ---
typo alg
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.