Created
February 22, 2014 14:53
-
-
Save altrive/9156060 to your computer and use it in GitHub Desktop.
This file contains 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
function Main | |
{ | |
#1.No attribute | |
$a = 5; | |
Write-Host ($a) #5 | |
#2.With Add Value attribute | |
[AddValue(5)] | |
$b = 5; | |
Write-Host $b #5+5 =10 | |
#3.Assign variable after declaration | |
[AddValue(5)] | |
$c = 1 + 1; | |
$c = 10 + 5 | |
Write-Host $c #15+5 = 20 | |
} | |
Add-Type -TypeDefinition @' | |
using System; | |
using System.Management.Automation; | |
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] | |
public class AddValueAttribute : ArgumentTransformationAttribute | |
{ | |
private int addValue; | |
public AddValueAttribute(int addValue) | |
{ | |
this.addValue = addValue; | |
} | |
public override object Transform(EngineIntrinsics engineIntrinsics, object inputData) | |
{ | |
return (int) inputData + addValue; | |
} | |
} | |
'@ | |
Main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment