V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
Accessing
V2EX  ›  问与答

如何在 PowerShell 中创建内部类?

  •  
  •   Accessing · 2020-10-16 11:10:14 +08:00 · 236 次点击
    这是一个创建于 1304 天前的主题,其中的信息可能已经有所发展或是发生改变。

    如何在 PowerShell 中创建内部类?

    PowerShell 版本是 7.0.3.

    搜索了很多资料都没有发现解决方案,但我自己倒有个变通的方案,这些内容在后面会有详细介绍.

    到底该怎么样在 PowerShell 中创建静态内部类?是不是目前 PowerShell 还没有这种机制?

    搜索不到相关内容

    我想在 PowerShell 中创建静态内部类,尝试在谷歌上搜索"PowerShell" "inner class",阅读about_Classes - PowerShell | Microsoft Docs,都没有发现有关的结果.

    使用 Java 语法无效

    在 Java 上的语法是这样的

    public class InnerClassTest {
        
        static class inner{
            
            
        }
    }
    
    

    但是在 PowerShell 中这样是不行的

    
    class myPath {
        static class ps {
            static $log = "LOG"
        }
    }
    
    

    输出的结果是

    ParserError: inner-class-0.ps1:3:17
    Line |
       3 |      static class ps {
         |                  ~
         | Missing '(' in class method parameter list.
    

    我目前的方式

    这样的方式可以达到类似的效果,不过 VSCode 没有办法对内部类中的成员提供智能提示,令人感到很遗憾.好在 Tab 可以检测到里面的成员.

    
    class myPathPs{
    
        static [string]$log = 'LOG'
    }
    
    class myPath {
        static [Object]$ps = [myPathPs]
    }
    
    [myPath]::ps::log
    
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2882 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 09:30 · PVG 17:30 · LAX 02:30 · JFK 05:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.