0

I have the following case:

Add-Type -TypeDefinition @'
    public  static  class MyClass1
    {
      [DllImport .... ]
      public static extern int MyClass1Function();
    }
'

class MyClass2 {
   static MyClass2Function() {
     [MyClass1]::MyClass1Function()  # this does not work (unable to find type)
   }
}

What is the proper syntax to call MyClass1::MyClass1Function() from MyClass2::MyClass2Function()?

Will I Am
  • 2,614
  • 3
  • 35
  • 61
  • Possible duplicate of [Using .Net Objects within a Powershell (V5) Class](https://stackoverflow.com/questions/34625440/using-net-objects-within-a-powershell-v5-class) – user4003407 Jun 05 '19 at 03:43

1 Answers1

1

I was able to do this using Invoke-Expression.

$something = '[MyClass1]::MyClass1Function();'
Invoke-Expression -command $something

Not pretty, but it does the job (using PS 5.0)

Will I Am
  • 2,614
  • 3
  • 35
  • 61