在Powershell中加载F#程序集并创建记录表达式

编程入门 行业动态 更新时间:2024-10-23 17:39:10
本文介绍了在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#程序集并创建记录表达式

本文发布于:2023-11-17 03:12:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608608.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表达式   加载   程序   Powershell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!