在Powershell中加载F#程序集并创建记录表达式 [英] Load F# assembly in Powershell and create a record expression

查看:68
本文介绍了在Powershell中加载F#程序集并创建记录表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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#程序集并创建记录表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆