问题
I have a Powershell
script. I successfully loaded a C#
assembly and used a method contained in one the classes in that assembly: [MyCSharpAssembly.MyClass]::MyAssemblyMethod()
. However the same did not work for F#
.
Is it at all possible?
I have an assembly called Data.dll
and it has a module called People.fs
and People.fs
defines record types:
module People =
type Teacher = {
FirstName:string,
LastName:string,
Age:int }
I want to load the Data.dll
assembly to my Powershell
script and then create a record expression of type Teacher inside the script to use it in some other calculation in that script.
How do I do that if it can be done?
回答1:
An F# record compiles to a read-only class, so you should be able to create a value using New-Object
, passing in the values as constructor arguments.
New-Object Teacher("Jane", "Doe", 27)
You may have to pass the fully-qualified name instead of Teacher
.
来源:https://stackoverflow.com/questions/32973438/load-f-assembly-in-powershell-and-create-a-record-expression