{"id":440,"date":"2008-01-31T22:51:50","date_gmt":"2008-01-31T21:51:50","guid":{"rendered":"http:\/\/soci.hu\/blog\/index.php\/2008\/01\/31\/powershell-custom-methods-and-properties\/"},"modified":"2008-01-31T22:51:50","modified_gmt":"2008-01-31T21:51:50","slug":"powershell-custom-methods-and-properties","status":"publish","type":"post","link":"https:\/\/soci.hu\/blog\/index.php\/2008\/01\/31\/powershell-custom-methods-and-properties\/","title":{"rendered":"Powershell Custom Methods and Properties"},"content":{"rendered":"<p>So\u00f3s Tibi powershellt tanul, ez lelkess\u00e9 tett engem is. \u00c9n ugyan m\u00e1r t\u00fal vagyok az alap szintaxon, de a p\u00e9ld\u00e1i kapcs\u00e1n \u00e9rdekel, mi t\u00f6rt\u00e9nik a h\u00e1tt\u00e9rben.<\/p>\n<p><a href=\"http:\/\/www.microsoft.com\/hun\/technet\/default.aspx?article=4ade1470-41ee-4b65-81c9-a109024ef278\">Legut\u00f3bb<\/a> ojjektumok properyj\u00e9t list\u00e1zgatta, form\u00e1zgatta. Nyilv\u00e1n .NET programol\u00f3k\u00e9nt tudjuk, hogy ez a reflection trivi\u00e1lis felhaszn\u00e1l\u00e1sa, de nem is ez a l\u00e9nyeg bel\u0151le. A k\u00e9rd\u00e9s akkor v\u00e1lt \u00e9rdekess\u00e9, amikor elkezdte rendeztetni a Hastable-ben lev\u0151 ojjektumokat ($result). A Hastable egy nagy ojjektumk\u00e9nt megy \u00e1t a cs\u00f6v\u00f6n, ez\u00e9rt azon nincs mit rendezni. A p\u00e9lda GetEnumerator() h\u00edv\u00e1sa ravasz tr\u00fckk. Ennek hat\u00e1s\u00e1ra a cs\u0151be behullanak a cuccosok mint DictionaryEntry ojjektumok. Ez m\u00e1r egy sima, sik t\u00f6mb, System.Array. Cool.<br \/>\nEzt k\u00e9ne rendeztetni, a Key propery alapj\u00e1n. Tibi viszont Name-et \u00edrt, \u00e9s j\u00f3l m\u0171k\u00f6d\u00f6tt. Ez elgondolkodtatott. Mi\u00e9rt megy ez j\u00f3l, mikor nincs is Name-je a DictionaryEntry-nek?<\/p>\n<p>No, h\u00e1t a c\u00edmbeli <a href=\"http:\/\/www.leeholmes.com\/blog\/AddCustomMethodsAndPropertiesToTypesInPowerShell.aspx\">Custom Methods and Property-k<\/a> miatt. Merthogy, a j\u00e1mbor rendszergazda a saj\u00e1t szem\u00fcveg\u00e9n kereszt\u00fcl l\u00e1tja a dolgokat, \u0151 nem programol\u00f3. Ez\u00e9rt egyes nehezen em\u00e9szthet\u0151 fogalmakat, mint Key \u00e1lnevekkel l\u00e1tnak el. Ezek xml f\u00e1jlokban vannak, pl. a types.ps1xml-ben van el\u00e9g sok. Konkr\u00e9t alanyunk \u00edgy n\u00e9z ki:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n   &lt;Type&gt;\r\n        &lt;Name&gt;System.Collections.DictionaryEntry&lt;\/Name&gt;\r\n        &lt;Members&gt;\r\n            &lt;AliasProperty&gt;\r\n                &lt;Name&gt;Name&lt;\/Name&gt;\r\n                &lt;ReferencedMemberName&gt;Key&lt;\/ReferencedMemberName&gt;\r\n            &lt;\/AliasProperty&gt;\r\n        &lt;\/Members&gt;\r\n    &lt;\/Type&gt;\r\n<\/pre>\n<p>Teccik l\u00e1tni, ez\u00e9rt \u00e9rti a Sort-Object a Key helyett a Name property-t.<\/p>\n<p>(A c\u00edmbe majdnem bedobtam a Microsoft Powers Hell viccet, de ez m\u00e1r szak\u00e1llas, nem?)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So\u00f3s Tibi powershellt tanul, ez lelkess\u00e9 tett engem is. \u00c9n ugyan m\u00e1r t\u00fal vagyok az alap szintaxon, de a p\u00e9ld\u00e1i kapcs\u00e1n \u00e9rdekel,&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,28,4],"tags":[],"class_list":["post-440","post","type-post","status-publish","format-standard","hentry","category-net","category-powershell","category-szakmai-elet"],"_links":{"self":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts\/440","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=440"}],"version-history":[{"count":0,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts\/440\/revisions"}],"wp:attachment":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=440"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=440"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=440"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}