{"id":14063995,"url":"https://github.com/LaurentDardenne/ExtensionMethod","last_synced_at":"2025-07-29T17:31:24.577Z","repository":{"id":174168715,"uuid":"81657076","full_name":"LaurentDardenne/ExtensionMethod","owner":"LaurentDardenne","description":"Creation of ps1xml file dedicated to the extension methods contained in an assembly.","archived":false,"fork":false,"pushed_at":"2024-01-01T19:15:45.000Z","size":1453,"stargazers_count":6,"open_issues_count":7,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-03T07:13:36.990Z","etag":null,"topics":["ets-xml","extension-methods","powershell","powershell-modules"],"latest_commit_sha":null,"homepage":null,"language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LaurentDardenne.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-11T14:11:29.000Z","updated_at":"2023-02-07T20:32:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"c32b35fb-c0b9-45aa-994e-716e9a0b5d5f","html_url":"https://github.com/LaurentDardenne/ExtensionMethod","commit_stats":null,"previous_names":["laurentdardenne/extensionmethod"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LaurentDardenne%2FExtensionMethod","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LaurentDardenne%2FExtensionMethod/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LaurentDardenne%2FExtensionMethod/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LaurentDardenne%2FExtensionMethod/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LaurentDardenne","download_url":"https://codeload.github.com/LaurentDardenne/ExtensionMethod/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228032919,"owners_count":17858917,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ets-xml","extension-methods","powershell","powershell-modules"],"created_at":"2024-08-13T07:03:36.893Z","updated_at":"2024-12-04T02:30:59.265Z","avatar_url":"https://github.com/LaurentDardenne.png","language":"PowerShell","funding_links":[],"categories":["PowerShell"],"sub_categories":[],"readme":"﻿# ExtensionMethod\n\nCreation of ps1xml file dedicated to the extension methods contained in an assembly.\nFrom an idea of [Bart De Smet's](http://bartdesmet.net/blogs/bart/archive/2007/09/06/extension-methods-in-windows-powershell.aspx)\n\nTo install this module :\n```Powershell\n\n$PSGalleryPublishUri = 'https://www.myget.org/F/ottomatt/api/v2/package'\n$PSGallerySourceUri = 'https://www.myget.org/F/ottomatt/api/v2'\n\nRegister-PSRepository -Name OttoMatt -SourceLocation $PSGallerySourceUri -PublishLocation $PSGalleryPublishUri #-InstallationPolicy Trusted\nInstall-Module ExtensionMethod -Repository OttoMatt\n```\n\nNote : this module depends on the [UncommonSense.PowerShell.TypeData](https://www.powershellgallery.com/packages/UncommonSense.PowerShell.TypeData) module, available on PSGallery.\n\nThis code return all types containing extension methods :\n\n```Powershell\n [psobject].Assembly.ExportedTypes|Find-ExtensionMethod -ExcludeGeneric|%  {$_.ToString()}\n\n#System.Management.Automation.Language.TokenFlags GetTraits(System.Management.Automation.Language.TokenKind)\n#Boolean HasTrait(System.Management.Automation.Language.TokenKind, System.Management.Automation.Language.TokenFlags)\n#System.String Text(System.Management.Automation.Language.TokenKind)\n```\n\nBy default Powershell can not use them, but with [ETS](https://github.com/MicrosoftDocs/PowerShell-Docs/tree/main/reference/docs-conceptual/developer/ets) it is possible to make extension methods available.\n\nThe goal is to adapt each method  :\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003cTypes\u003e\n  \u003cType\u003e\n    \u003cName\u003eSystem.Management.Automation.Language.TokenKind\u003c/Name\u003e\n    \u003cMembers\u003e\n      \u003cScriptMethod\u003e\n         \u003cName\u003eHasTrait\u003c/Name\u003e\n       \u003cScript\u003e\n         switch ($args.Count) {\n            1 { [System.Management.Automation.Language.TokenTraits]::HasTrait($this,$args[0])}\n\n            default { throw \"No overload for 'HasTrait' takes the specified number of parameters ($($args.Count)).\" }\n         }\u003c/Script\u003e\n      \u003c/ScriptMethod\u003e\n      \u003cScriptMethod\u003e\n        \u003cName\u003eGetTrait\u003c/Name\u003e\n             ...\n```\n\nThus it is possible to write :\n\n```Powershell\n$code.Ast.EndBlock.BlockKind.HasTrait('MemberName')\n```\n\nThe **New-ExtendedTypeData** function create one or many files from the extension methods contained in an assembly\n\n```Powershell\nAdd-Type -Path $AssemblyPath -Pass|\n New-ExtendedTypeData -Path c:\\temp\\TestPs1Xml\\All.ps1xml -All\n\nWARNING: Excluded method : System.Boolean.ToString()\nWARNING: Excluded method : System.Object.ToString()\nWARNING: Excluded method : System.Char.ToString()\n```\n\n**NOTE**:\nThe ToString() method can be generate recursiv call, they are excluded.\nThe generic methods and those returning a type Interface are excluded.\n\nThe _-All_ parameter group all definitions to a single file :\n\n```Powershell\ndir  -Path c:\\temp\\TestPs1Xml\n\n    Directory: C:\\temp\\TestPs1Xml\n\nMode                LastWriteTime         Length Name\n----                -------------         ------ ----\n-a----       16/02/2017     12:57         269651 All.ps1xml\n```\n\nThe absence of the _-All_ parameter creates a file by type, the filename is the name of the corresponding type :\n\n```Powershell\nAdd-Type -Path $AssemblyPath -Pass|\n New-ExtendedTypeData -Path c:\\temp\\TestPs1Xml\\All.ps1xml\n\ndir  -Path c:\\temp\\TestPs1Xml|more\n\n    Directory: C:\\temp\\TestPs1Xml\n\nMode                LastWriteTime         Length Name\n----                -------------         ------ ----\n-a----       16/02/2017     12:57         269651 All.ps1xml\n-a----       16/02/2017     13:07           5636 System.Array.ps1xml\n-a----       16/02/2017     13:07           1098 System.Boolean.ps1xml\n-a----       16/02/2017     13:07           1122 System.Byte.ps1xml\n-a----       16/02/2017     13:07           4404 System.Byte.Array.ps1xml\n-a----       16/02/2017     13:07           8636 System.Char.ps1xml\n-a----       16/02/2017     13:07            509 System.Collections.Specialized.NameValueCollection.ps1xml\n-a----       16/02/2017     13:07            864 System.Data.Common.DbCommand.ps1xml\n-a----       16/02/2017     13:07           3736 System.Data.Common.DbConnection.ps1xml\n...\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLaurentDardenne%2FExtensionMethod","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FLaurentDardenne%2FExtensionMethod","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLaurentDardenne%2FExtensionMethod/lists"}