Original article address:Http://app.en25.com/e/es.aspx? S = 1403 & E = 5072 & elq = a8251b41fe1a4d6297a0aecd8e466373
Original article:
Did you know that you can compile any. net source code on the fly and use this to create your own types? Here is an example between strating how to create a new type from C # code that has both static and dynamic methods:
$ Source = @'
Public class Calculator
{
Public static int add (int A, int B)
{
Return (A + B );
}
Public int multiply (int A, int B)
{
Return (A * B );
}
}
'@
Add-type-typedefinition $ Source
[Calculator]
[Calculator] :: Add (5, 10)
$ Mycalculator = New-Object Calculator
$ Mycalculator . Multiply (3, 12)
Translation:
you know you can compile any real-time . net Source Code and use them as your custom types? The following example illustrates how to use C # Create a type with static methods and instance methods:
$ Source = @'
Public class Calculator
{
Public static int add (int A, int B)
{
Return (A + B );
}
Public int multiply (int A, int B)
{
Return (A * B );
}
}
'@
Add-type-typedefinition $ Source
[Calculator]
[Calculator] :: Add (5, 10)
$ Mycalculator = New-Object Calculator
$ Mycalculator . Multiply (3, 12)
Notes:
Directly inPSCodeCreate a class.
Review. NetStatic Method of the class and call method of the instance method.
I personally prefer to compile the logicDLLThenPS.