Load F# assembly in Powershell and create a record expression

*爱你&永不变心* 提交于 2019-12-07 09:40:07

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!