Monday, 16 May 2016

Run a C# .cs file from a Powershell Script

$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);
     }
   }
"@

# type definition - must be declared
Add-Type -TypeDefinition $source
 

# access a static method
[BasicTest]::Add(4, 3)

# create instance of class and call a non-static method
$basicTestObject = New-Object BasicTest
$basicTestObject.Multiply(5, 2)



No comments:

SQL: Generate a range of numbers

SELECT ones.n + 10*tens.n + 100*hundreds.n + 1000*thousands.n FROM       (VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) ones(n),      (VALU...