Skip to content

Instantly share code, notes, and snippets.

@constructor-igor
Created December 2, 2014 16:22
Show Gist options
  • Select an option

  • Save constructor-igor/55dfcd91c393d2c06e4f to your computer and use it in GitHub Desktop.

Select an option

Save constructor-igor/55dfcd91c393d2c06e4f to your computer and use it in GitHub Desktop.
Can I write a class using powershell?
#
# http://stackoverflow.com/questions/6848741/can-i-write-a-class-using-powershell
#
C:\PS>$source = @"
public class BasicTest
{
public static int Add(int a, int b)
{
return (a + b);
}
public int Multiply(int a, int b)
{
return (a * b);
}
}
"@
C:\PS> Add-Type -TypeDefinition $source
C:\PS> [BasicTest]::Add(4, 3)
C:\PS> $basicTestObject = New-Object BasicTest
C:\PS> $basicTestObject.Multiply(5, 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment