PoshCode Archive  Artifact [f87012ff75]

Artifact f87012ff75a8ae8f5acf5132d6588dfce7c470c0a2e8fde0bffc8cdda21bd4f7:

  • File demo-attributes.ps1 — part of check-in [1ab9caf26c] at 2018-06-10 13:11:39 on branch trunk — a demo of using some build in dotnet attributes to store some powershell METADATA (hashtables) and extract that. (user: karl prosser size: 1007)

# encoding: ascii
# api: powershell
# title: demo-attributes
# description: a demo of using some build in dotnet attributes to store some powershell METADATA (hashtables) and extract that.
# version: 0.1
# type: function
# author: karl prosser
# license: CC0
# function: demo-attributes
# x-poshcode-id: 2511
# x-archived: 2013-01-11T06:32:21
# x-published: 2013-02-17T16:01:00
#
#
function demo-attributes
{

[System.Configuration.SettingsDescription({
    @{something = 1;
      this = 'that';
      array = (1,2,3);
      sub = @{ sub1 = 1 ; sub2 =2 }
    }})]
    
[CmdletBinding(DefaultParameterSetName="noname")]
param (
 [Parameter(Position=1,mandatory = $true)]
  [string]$something 
 
)
1..10
}
$settingstext = ((dir function:\demo-attributes).scriptblock.attributes |Where-Object { $_.typeid -like '*settingsdescription*'  }).description
$settingsscriptblock = $ExecutionContext.InvokeCommand.NewScriptBlock("DATA {" + $settingstext + "}")
&$settingsscriptblock