Created
December 2, 2014 16:22
-
-
Save constructor-igor/55dfcd91c393d2c06e4f to your computer and use it in GitHub Desktop.
Can I write a class using powershell?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # 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