我有一个Powershell脚本.我成功加载了C#程序集,并使用了该程序集中的类中的方法:[MyCSharpAssembly.MyClass]::MyAssemblyMethod().但是对于F#来说,这是行不通的.
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#.
有可能吗?
我有一个名为Data.dll的程序集,它有一个名为People.fs的模块,而People.fs定义了记录类型:
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 }我想将Data.dll程序集加载到我的Powershell脚本中,然后在脚本中创建类型为Teacher的记录表达式,以在该脚本的其他计算中使用它.
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?
推荐答案F#记录编译为只读类,因此您应该能够使用New-Object创建值,并将值作为构造函数参数传递.
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)您可能必须通过标准名称而不是Teacher.
You may have to pass the fully-qualified name instead of Teacher.
更多推荐
在Powershell中加载F#程序集并创建记录表达式
发布评论