如何在 PowerShell v5 模块中导出类

编程入门 行业动态 更新时间:2024-10-27 00:25:56
本文介绍了如何在 PowerShell v5 模块中导出类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个模块设置,就像其他一些脚本的库一样.我不知道如何将类声明放入调用 导入模块.我试图用 -class 参数安排 Export-Module,就像 -function,但没有 -class 可用.我是否只需要在每个脚本中声明类?

I've got a module setup to be like a library for a few other scripts. I can't figure out how to get a class declaration into the script scope calling Import-Module. I tried to arrange Export-Module with a -class argument, like the -function, but there isn't a -class available. Do I just have to declare the class in every script?

设置:

  • holidays.psm1 位于 ~\documents\windows\powershell\modules\holidays\
  • 活动脚本调用导入模块假期
  • holiday.psm1 中有另一个函数可以正确返回类对象,但我不知道如何在导入后从活动脚本创建类的新成员

这是类的样子:

Class data_block { $array $rows $cols data_block($a, $r, $c) { $this.array = $a $this.rows = $r $this.cols = $c } }

推荐答案

根据此处和这里,您可以通过在 PowerShell 5 中执行以下操作来使用模块中定义的类:

According to here and here, you can use classes defined in your module by doing the following in PowerShell 5:

using module holidays

更多推荐

如何在 PowerShell v5 模块中导出类

本文发布于:2023-11-02 17:58:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1553042.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模块   如何在   PowerShell

发布评论

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

>www.elefans.com

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