{"id":6191,"date":"2008-05-10T11:06:56","date_gmt":"2008-05-10T11:06:56","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2008\/05\/10\/in-praise-of-typeconverters-spread-the-love\/"},"modified":"2019-02-18T13:15:57","modified_gmt":"2019-02-18T20:15:57","slug":"in-praise-of-typeconverters-spread-the-love","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/in-praise-of-typeconverters-spread-the-love\/","title":{"rendered":"In Praise of TypeConverters &#8211; Spread the Love"},"content":{"rendered":"<p>I just got through reading Scott Hanselman&#8217;s blog entry:&#160; <a href=\"http:\/\/www.hanselman.com\/blog\/TypeConvertersTheresNotEnoughTypeDescripterGetConverterInTheWorld.aspx\">TypeConverters: There&#8217;s not enough TypeDescripter.GetConverter<\/a> in which he referenced&#160; Jesse Liberty&#8217;s blog entry: <a href=\"http:\/\/silverlight.net\/blogs\/jesseliberty\/archive\/2008\/01\/02\/did-you-know-that-type-converters-allow-you-to-use-property-attributes-in-complex-types.aspx\">Did You Know That&#8230; Type Converters allow you to use property attributes in Complex Types<\/a> and decided to pile on.<\/p>\n<p><strong>Developers<\/strong> &#8211; you should stop what you are doing and get TypeConverters in focus.&#160; Here is the big picture way to think about it:&#160; As developers, our mission in life is to make the lives of others easier by providing them the functions they need in they way they need them.&#160; TypeConverters play a huge role in the mission.<\/p>\n<p>TypeConverters are one of the many the unsung heroes behind the magic of PowerShell.&#160; Think about the code you write, think about the code your customers write.&#160; An amazing amount of time and effort goes into coding around impendence mismatches:<\/p>\n<ul>\n<li>That API gave me an A but this API needs a B.<\/li>\n<li>I can easily get a string but I need an object of type A.<\/li>\n<\/ul>\n<p>This impendence mismatches cause conceptual and code friction.&#160; Think of TypeConverters as the grease in the object model that make things work together easily.&#160; As a developer, you should take a look at the code you\/your customers have to write and consider where a typeconverter could make things easier.&#160; <\/p>\n<p>Traditional languages have the disadvantage of requiring the developer to know about and use the TypeConverter.&#160; The magic of PowerShell is that we do all of that for the user.&#160; We know the TYPE of the data that the user has and we know what TYPE is needed.&#160; We&#8217;ll go through lots of hoops to make things &quot;just work&quot; including calling constructors, Parse() methods and TypeConverters.&#160; Abhishek Agrawal wrote a good blog <a href=\"http:\/\/abhishek225.spaces.live.com\/Blog\/cns!13469C7B7CE6E911!191.entry?wa=wsignin1.0\">Extending PowerShell with Customer TypeConverters<\/a> where he describes how to write a TypeConverter and then how to register it with PowerShell so we can use it in our type coercion engine.<\/p>\n<p><strong>Users:<\/strong>&#160; I&#8217;d love to hear from you about any examples where you think we should have type convertors and don&#8217;t.<\/p>\n<p>Cheers!<\/p>\n<p>Jeffrey Snover [MSFT]   <br \/>Windows Management Partner Architect    <br \/>Visit the Windows PowerShell Team blog at:&#160;&#160;&#160; <a href=\"http:\/\/blogs.msdn.com\/PowerShell\">http:\/\/blogs.msdn.com\/PowerShell<\/a>    <br \/>Visit the Windows PowerShell ScriptCenter at:&#160; <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx\">http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I just got through reading Scott Hanselman&#8217;s blog entry:&#160; TypeConverters: There&#8217;s not enough TypeDescripter.GetConverter in which he referenced&#160; Jesse Liberty&#8217;s blog entry: Did You Know That&#8230; Type Converters allow you to use property attributes in Complex Types and decided to pile on. Developers &#8211; you should stop what you are doing and get TypeConverters in [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6191","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"blog_post_summary":"<p>I just got through reading Scott Hanselman&#8217;s blog entry:&#160; TypeConverters: There&#8217;s not enough TypeDescripter.GetConverter in which he referenced&#160; Jesse Liberty&#8217;s blog entry: Did You Know That&#8230; Type Converters allow you to use property attributes in Complex Types and decided to pile on. Developers &#8211; you should stop what you are doing and get TypeConverters in [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/6191","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=6191"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/6191\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=6191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=6191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=6191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}