How to add type definition before parsing a class?

91 Views Asked by At

I have A Powershell code that includes a TypeDefinition and a custom class like below sample. This throws an error, when I want to execute that code, because the PS-parser checks the class before the TypeDefinition. If I manually execute only the TypeDefinition and run the full code after that, then all works as expected.

How can I change the code in that way, that it will run in one go?

add-type -TypeDefinition @"
using System;
public static class MeaningOf {
    public const Int32 Life = 42;
}
"@

class Planet {
    [void] earth() {
        $result = [MeaningOf]::Life
    }
}
0

There are 0 best solutions below