<?xml version="1.0" encoding="iso-8859-1"?><!-- generator="b2evolution/4.0.3" -->
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Desktop Developer - Author(s): Christiaan Baes (chrissie1)</title>
		<link>http://blogs.lessthandot.com/index.php/DesktopDev/</link>
		<atom:link rel="self" type="application/rss+xml" href="http://blogs.lessthandot.com/index.php/DesktopDev/?tempskin=_rss2" />
		<description></description>
		<language>en-GB</language>
		<docs>http://blogs.law.harvard.edu/tech/rss</docs>
		<admin:generatorAgent rdf:resource="http://b2evolution.net/?v=4.0.3"/>
		<ttl>60</ttl>
				<item>
			<title>Fody Anotar weaving and logging combined into one package.</title>
			<link>http://blogs.lessthandot.com/index.php/DesktopDev/MSTech/VBNET/fody-anotar-weaving-and-logging</link>
			<pubDate>Thu, 25 Apr 2013 06:53:00 +0000</pubDate>			<dc:creator>Christiaan Baes (chrissie1)</dc:creator>
			<category domain="alt">Microsoft Technologies</category>
<category domain="main">VB.NET</category>			<guid isPermaLink="false">2183@http://blogs.lessthandot.com/</guid>
						<description>&lt;h2&gt;Introduction&lt;/h2&gt;

&lt;p&gt;I said it once and I will say it again. Logging is very important once your app goes live. It&#039;s the best way for you to find out what the user did to destroy your sanity. &lt;br /&gt;
I am always on the lookout for new and exiting things that will make logging easier for me. I want less code but maximum information. &lt;br /&gt;
You can get lots of information with &lt;a href=&quot;http://blogs.lessthandot.com/index.php/All/?p=2162&quot;&gt;Gibraltar&#039;s Loupe&lt;/a&gt; but you can get even less code and more information with &lt;a href=&quot;https://github.com/Fody/Anotar&quot;&gt;Anotar&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;The code&lt;/h2&gt;

&lt;p&gt;It&#039;s easy.&lt;/p&gt;

&lt;p&gt;Just add the Anotar.Nlog package from nuget and then add some config for nlog. Like this.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;xml&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;xml&quot; id=&quot;cb95695&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;?xml&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;version&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;encoding&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;utf-8&amp;quot;&lt;/span&gt; &lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;configuration&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;configSections&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;section&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;name&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;nlog&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;type&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;NLog.Config.ConfigSectionHandler, NLog&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/configSections&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;startup&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;supportedRuntime&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;version&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;v4.0&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;sku&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;.NETFramework,Version=v4.5&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/startup&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;system&lt;/span&gt;.serviceModel&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;bindings&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;client&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/system&lt;/span&gt;.serviceModel&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;nlog&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;targets&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;target&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;name&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;file&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;type&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;File&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;fileName&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;_${level}.log&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;layout&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;${longdate} ${threadid} [${level:uppercase=true}] ${message}&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;archiveFileName&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;_${level}.{#}.log&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;archiveAboveSize&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;1048576&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;archiveNumbering&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Sequence&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;maxArchiveFiles&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;10&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;concurrentWrites&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;keepFileOpen&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;false&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;encoding&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;iso-8859-2&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/targets&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;rules&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;logger&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;name&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;*&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;minlevel&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;Debug&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;writeTo&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;file&amp;quot;&lt;/span&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/rules&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/nlog&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;/configuration&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb14306&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And try it with this code.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;vbnet&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;vbnet&quot; id=&quot;cb95680&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;Module&lt;/span&gt; Module1&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt; Main&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Dim&lt;/span&gt; l &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;New&lt;/span&gt; Logthing&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; l.&lt;span style=&quot;color: #000000;&quot;&gt;TestSub&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.&lt;span style=&quot;color: #000000;&quot;&gt;WriteLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;l.&lt;span style=&quot;color: #000000;&quot;&gt;TestFunction&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Anotar.&lt;span style=&quot;color: #000000;&quot;&gt;NLog&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;Log&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;Info&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;Some info in a static method&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Public&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Class&lt;/span&gt; Logthing&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Public&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt; TestSub&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Anotar.&lt;span style=&quot;color: #000000;&quot;&gt;NLog&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;Log&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;Debug&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;My message for sub&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Public&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Function&lt;/span&gt; TestFunction&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;String&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Anotar.&lt;span style=&quot;color: #000000;&quot;&gt;NLog&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;Log&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;Debug&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;My message for function&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Return &lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;This thing&amp;quot;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Function&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Class&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Module&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb58820&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This is then the resulting debug log file.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;2013-04-25 13:24:00.1197 8 [DEBUG] Method: &#039;System.Void ConsoleApplication1.Module1/Logthing::TestSub()&#039;. Line: ~12. My message for sub&lt;br /&gt;
2013-04-25 13:24:00.1387 8 [DEBUG] Method: &#039;System.String ConsoleApplication1.Module1/Logthing::TestFunction()&#039;. Line: ~16. My message for function&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;And the info file.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;2013-04-25 13:24:00.1387 8 [INFO] Method: &#039;System.Void ConsoleApplication1.Module1::Main()&#039;. Line: ~7. Some info in a static method&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;The lines seem to be correct and the other information too. &lt;/p&gt;

&lt;p&gt;But how does Fody do it?&lt;/p&gt;

&lt;p&gt;Well, it changes your code at compile time. &lt;/p&gt;

&lt;p&gt;This for instance is the LogThing class after a decompile by JustDecompile.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;vbnet&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;vbnet&quot; id=&quot;cb3978&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;Public&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Class&lt;/span&gt; Logthing&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Private&lt;/span&gt; Shared AnotarLogger &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; Logger&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; Shared &lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;New&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Logthing.&lt;span style=&quot;color: #000000;&quot;&gt;AnotarLogger&lt;/span&gt; = LogManager.&lt;span style=&quot;color: #000000;&quot;&gt;GetLogger&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;ConsoleApplication1.Module1/Logthing&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;lt;DebuggerNonUserCode&amp;gt; _&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Public&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;New&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;MyBase&lt;/span&gt;.&lt;span style=&quot;color: #0600FF;&quot;&gt;New&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Public&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Function&lt;/span&gt; TestFunction&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;String&lt;/span&gt; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Dim&lt;/span&gt; V_2 &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; Object&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; = &lt;span style=&quot;color: #0600FF;&quot;&gt;New&lt;/span&gt; Object&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Dim&lt;/span&gt; V_1 &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;String&lt;/span&gt; = &lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;My message for function&amp;quot;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; V_1 = &lt;span style=&quot;color: #0600FF;&quot;&gt;String&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;Concat&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;Method: &#039;System.String ConsoleApplication1.Module1/Logthing::TestFunction()&#039;. Line: ~16. &amp;quot;&lt;/span&gt;, V_1&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Logthing.&lt;span style=&quot;color: #000000;&quot;&gt;AnotarLogger&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;Debug&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;V_1, V_2&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Dim&lt;/span&gt; TestFunction &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;String&lt;/span&gt; = &lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;This thing&amp;quot;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Return TestFunction&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Function&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Public&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt; TestSub&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Dim&lt;/span&gt; V_1 &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; Object&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; = &lt;span style=&quot;color: #0600FF;&quot;&gt;New&lt;/span&gt; Object&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Dim&lt;/span&gt; V_0 &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;String&lt;/span&gt; = &lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;My message for sub&amp;quot;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; V_0 = &lt;span style=&quot;color: #0600FF;&quot;&gt;String&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;Concat&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;Method: &#039;System.Void ConsoleApplication1.Module1/Logthing::TestSub()&#039;. Line: ~12. &amp;quot;&lt;/span&gt;, V_0&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Logthing.&lt;span style=&quot;color: #000000;&quot;&gt;AnotarLogger&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;Debug&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;V_0, V_1&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Class&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb83083&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt; &lt;/p&gt;

&lt;p&gt;As you can see it is not doing any reflection in your code. It just replaces your Log.Debug code with other code. Which means it should be faster at runtime. &lt;/p&gt;

&lt;p&gt;This also means that compiling will be slower, because it has to change your code. How much? No idea. &lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;I like this.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DesktopDev/MSTech/VBNET/fody-anotar-weaving-and-logging&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<h2>Introduction</h2>

<p>I said it once and I will say it again. Logging is very important once your app goes live. It's the best way for you to find out what the user did to destroy your sanity. <br />
I am always on the lookout for new and exiting things that will make logging easier for me. I want less code but maximum information. <br />
You can get lots of information with <a href="http://blogs.lessthandot.com/index.php/All/?p=2162">Gibraltar's Loupe</a> but you can get even less code and more information with <a href="https://github.com/Fody/Anotar">Anotar</a>.</p>

<h2>The code</h2>

<p>It's easy.</p>

<p>Just add the Anotar.Nlog package from nuget and then add some config for nlog. Like this.</p>

<div class="codebox"><div class="codeheader"><span>xml</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb41084'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb41084','cb6921'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="xml" id="cb41084" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span> <span style="font-weight: bold; color: black;">?&gt;</span></span></li><li style="" class="li2"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;configuration<span style="font-weight: bold; color: black;">&gt;</span></span></span></li><li style="" class="li1">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;configSections<span style="font-weight: bold; color: black;">&gt;</span></span></span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;section</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;nlog&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;NLog.Config.ConfigSectionHandler, NLog&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span></li><li style="" class="li1">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/configSections<span style="font-weight: bold; color: black;">&gt;</span></span></span></li><li style="" class="li2">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;startup<span style="font-weight: bold; color: black;">&gt;</span></span></span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;supportedRuntime</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;v4.0&quot;</span> <span style="color: #000066;">sku</span>=<span style="color: #ff0000;">&quot;.NETFramework,Version=v4.5&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span></li><li style="" class="li2">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/startup<span style="font-weight: bold; color: black;">&gt;</span></span></span></li><li style="" class="li1">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;system</span>.serviceModel<span style="font-weight: bold; color: black;">&gt;</span></span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bindings</span><span style="font-weight: bold; color: black;">/&gt;</span></span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;client</span><span style="font-weight: bold; color: black;">/&gt;</span></span></li><li style="" class="li2">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/system</span>.serviceModel<span style="font-weight: bold; color: black;">&gt;</span></span></li><li style="" class="li1">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;nlog<span style="font-weight: bold; color: black;">&gt;</span></span></span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;targets<span style="font-weight: bold; color: black;">&gt;</span></span></span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;file&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;File&quot;</span> <span style="color: #000066;">fileName</span>=<span style="color: #ff0000;">&quot;_${level}.log&quot;</span> <span style="color: #000066;">layout</span>=<span style="color: #ff0000;">&quot;${longdate} ${threadid} [${level:uppercase=true}] ${message}&quot;</span> <span style="color: #000066;">archiveFileName</span>=<span style="color: #ff0000;">&quot;_${level}.{#}.log&quot;</span> <span style="color: #000066;">archiveAboveSize</span>=<span style="color: #ff0000;">&quot;1048576&quot;</span> <span style="color: #000066;">archiveNumbering</span>=<span style="color: #ff0000;">&quot;Sequence&quot;</span> <span style="color: #000066;">maxArchiveFiles</span>=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #000066;">concurrentWrites</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">keepFileOpen</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;iso-8859-2&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/targets<span style="font-weight: bold; color: black;">&gt;</span></span></span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;rules<span style="font-weight: bold; color: black;">&gt;</span></span></span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;logger</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;*&quot;</span> <span style="color: #000066;">minlevel</span>=<span style="color: #ff0000;">&quot;Debug&quot;</span> <span style="color: #000066;">writeTo</span>=<span style="color: #ff0000;">&quot;file&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/rules<span style="font-weight: bold; color: black;">&gt;</span></span></span></li><li style="" class="li2">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/nlog<span style="font-weight: bold; color: black;">&gt;</span></span></span></li><li style="" class="li1"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/configuration<span style="font-weight: bold; color: black;">&gt;</span></span></span></li></ol></div><div id="cb6921" style="display: none; color: red;"></div></div></div>

<p>And try it with this code.</p>

<div class="codebox"><div class="codeheader"><span>vbnet</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb91552'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb91552','cb2537'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="vbnet" id="cb91552" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0600FF;">Module</span> Module1</li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #0600FF;">Sub</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> l <span style="color: #0600FF;">As</span> <span style="color: #0600FF;">New</span> Logthing</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; l.<span style="color: #000000;">TestSub</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #000000;">WriteLine</span><span style="color: #000000;">&#40;</span>l.<span style="color: #000000;">TestFunction</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; Anotar.<span style="color: #000000;">NLog</span>.<span style="color: #000000;">Log</span>.<span style="color: #000000;">Info</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">&quot;Some info in a static method&quot;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #0600FF;">Public</span> <span style="color: #0600FF;">Class</span> Logthing</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Public</span> <span style="color: #0600FF;">Sub</span> TestSub<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Anotar.<span style="color: #000000;">NLog</span>.<span style="color: #000000;">Log</span>.<span style="color: #000000;">Debug</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">&quot;My message for sub&quot;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Public</span> <span style="color: #0600FF;">Function</span> TestFunction<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">As</span> <span style="color: #0600FF;">String</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Anotar.<span style="color: #000000;">NLog</span>.<span style="color: #000000;">Log</span>.<span style="color: #000000;">Debug</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">&quot;My message for function&quot;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return <span style="color: #0600FF;">&quot;This thing&quot;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Function</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Class</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Module</span></li></ol></div><div id="cb2537" style="display: none; color: red;"></div></div></div>

<p>This is then the resulting debug log file.</p>

<blockquote><p>2013-04-25 13:24:00.1197 8 [DEBUG] Method: 'System.Void ConsoleApplication1.Module1/Logthing::TestSub()'. Line: ~12. My message for sub<br />
2013-04-25 13:24:00.1387 8 [DEBUG] Method: 'System.String ConsoleApplication1.Module1/Logthing::TestFunction()'. Line: ~16. My message for function</p></blockquote>

<p>And the info file.</p>

<blockquote><p>2013-04-25 13:24:00.1387 8 [INFO] Method: 'System.Void ConsoleApplication1.Module1::Main()'. Line: ~7. Some info in a static method</p></blockquote>

<p>The lines seem to be correct and the other information too. </p>

<p>But how does Fody do it?</p>

<p>Well, it changes your code at compile time. </p>

<p>This for instance is the LogThing class after a decompile by JustDecompile.</p>

<div class="codebox"><div class="codeheader"><span>vbnet</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb12270'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb12270','cb61457'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="vbnet" id="cb12270" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0600FF;">Public</span> <span style="color: #0600FF;">Class</span> Logthing</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #0600FF;">Private</span> Shared AnotarLogger <span style="color: #0600FF;">As</span> Logger</li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; Shared <span style="color: #0600FF;">Sub</span> <span style="color: #0600FF;">New</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; Logthing.<span style="color: #000000;">AnotarLogger</span> = LogManager.<span style="color: #000000;">GetLogger</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">&quot;ConsoleApplication1.Module1/Logthing&quot;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; &lt;DebuggerNonUserCode&gt; _</li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #0600FF;">Public</span> <span style="color: #0600FF;">Sub</span> <span style="color: #0600FF;">New</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">MyBase</span>.<span style="color: #0600FF;">New</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #0600FF;">Public</span> <span style="color: #0600FF;">Function</span> TestFunction<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">As</span> <span style="color: #0600FF;">String</span> </li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> V_2 <span style="color: #0600FF;">As</span> Object<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> = <span style="color: #0600FF;">New</span> Object<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> V_1 <span style="color: #0600FF;">As</span> <span style="color: #0600FF;">String</span> = <span style="color: #0600FF;">&quot;My message for function&quot;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; V_1 = <span style="color: #0600FF;">String</span>.<span style="color: #000000;">Concat</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">&quot;Method: 'System.String ConsoleApplication1.Module1/Logthing::TestFunction()'. Line: ~16. &quot;</span>, V_1<span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; Logthing.<span style="color: #000000;">AnotarLogger</span>.<span style="color: #000000;">Debug</span><span style="color: #000000;">&#40;</span>V_1, V_2<span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> TestFunction <span style="color: #0600FF;">As</span> <span style="color: #0600FF;">String</span> = <span style="color: #0600FF;">&quot;This thing&quot;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; Return TestFunction</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Function</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #0600FF;">Public</span> <span style="color: #0600FF;">Sub</span> TestSub<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> V_1 <span style="color: #0600FF;">As</span> Object<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> = <span style="color: #0600FF;">New</span> Object<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> V_0 <span style="color: #0600FF;">As</span> <span style="color: #0600FF;">String</span> = <span style="color: #0600FF;">&quot;My message for sub&quot;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; V_0 = <span style="color: #0600FF;">String</span>.<span style="color: #000000;">Concat</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">&quot;Method: 'System.Void ConsoleApplication1.Module1/Logthing::TestSub()'. Line: ~12. &quot;</span>, V_0<span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; Logthing.<span style="color: #000000;">AnotarLogger</span>.<span style="color: #000000;">Debug</span><span style="color: #000000;">&#40;</span>V_0, V_1<span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></li><li style="" class="li2"><span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Class</span></li></ol></div><div id="cb61457" style="display: none; color: red;"></div></div></div><p> </p>

<p>As you can see it is not doing any reflection in your code. It just replaces your Log.Debug code with other code. Which means it should be faster at runtime. </p>

<p>This also means that compiling will be slower, because it has to change your code. How much? No idea. </p>

<h2>Conclusion</h2>

<p>I like this.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DesktopDev/MSTech/VBNET/fody-anotar-weaving-and-logging">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DesktopDev/MSTech/VBNET/fody-anotar-weaving-and-logging#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DesktopDev/?tempskin=_rss2&#38;disp=comments&#38;p=2183</wfw:commentRss>
		</item>
				<item>
			<title>ServiceStack.Text has a nice extension method called Dump and it has a few friends</title>
			<link>http://blogs.lessthandot.com/index.php/DesktopDev/MSTech/servicestack-text-has-a-nice</link>
			<pubDate>Mon, 31 Dec 2012 07:49:00 +0000</pubDate>			<dc:creator>Christiaan Baes (chrissie1)</dc:creator>
			<category domain="main">Microsoft Technologies</category>
<category domain="alt">C#</category>			<guid isPermaLink="false">1999@http://blogs.lessthandot.com/</guid>
						<description>&lt;h2&gt;Introduction&lt;/h2&gt;

&lt;p&gt;Yesterday I was &lt;a href=&quot;http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/nancy-and-returning-a-pdf&quot;&gt;adding a pdf feature to my Nancy service&lt;/a&gt;. And I was outputting my objects to the pdf like this.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;csharp&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;csharp&quot; id=&quot;cb20335&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;foreach&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;var prop &lt;span style=&quot;color: #0600FF;&quot;&gt;in&lt;/span&gt; model.&lt;span style=&quot;color: #0000FF;&quot;&gt;GetType&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;GetProperties&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; oDoc.&lt;span style=&quot;color: #0000FF;&quot;&gt;Add&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.google.com/search?q=new+msdn.microsoft.com&quot;&gt;&lt;span style=&quot;color: #008000;&quot;&gt;new&lt;/span&gt;&lt;/a&gt; Paragraph&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;prop.&lt;span style=&quot;color: #0000FF;&quot;&gt;Name&lt;/span&gt; + &lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;:&amp;quot;&lt;/span&gt; + prop.&lt;span style=&quot;color: #0000FF;&quot;&gt;GetValue&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;model&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;ToString&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;; &amp;nbsp; &amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb80878&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;But we all know this is far from finished and will only work in the most simple of cases, once you add complex types to your type the results will be less than optimal.&lt;/p&gt;

&lt;p&gt;Of course you are not alone in this world and other people have had to do this to. And Demis Bellot even made a nuget package out of his solution. So here is Servicestack.Text and the &lt;a href=&quot;http://www.servicestack.net/mythz_blog/?p=202&quot;&gt;Dump &lt;/a&gt;extension method and friends.&lt;/p&gt;

&lt;h2&gt;Dump&lt;/h2&gt;

&lt;p&gt;So go ahead and look for servicestack.text on nuget and add it to your project.&lt;/p&gt;

&lt;p&gt;First of all I would like to change my method above to use the Dump() method.&lt;/p&gt;

&lt;p&gt;And so my method now looks like this.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;chsarp&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;chsarp&quot; id=&quot;cb19349&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;protected virtual Action&amp;lt;Stream&amp;gt; GetPdfContents(TModel model)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return stream =&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var oDoc = new Document(PageSize.A4);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PdfWriter.GetInstance(oDoc, stream);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; oDoc.Open();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; oDoc.Add(new Paragraph(model.Dump())); &amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; oDoc.Close();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; };&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb31679&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So you just need you object and call the Dump() extension method on it and the output will look like this.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;{&lt;br /&gt;
propertyname: value,&lt;br /&gt;
propertyname2: value&lt;br /&gt;
}&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Nicely formatted JSV.&lt;br /&gt;
 &lt;br /&gt;
Yep that&#039;s it.&lt;/p&gt;

&lt;p&gt;The output now looks like this.&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/users/chrissie1/servicestacktext/servicestacktext1.png?mtime=1356945714&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/users/chrissie1/servicestacktext/servicestacktext1.png?mtime=1356945714&quot; width=&quot;532&quot; height=&quot;670&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;Or I could output a list of objects and that would look like this.&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/users/chrissie1/servicestacktext/servicestacktext2.png?mtime=1356945965&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/users/chrissie1/servicestacktext/servicestacktext2.png?mtime=1356945965&quot; width=&quot;594&quot; height=&quot;723&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;And that is very convenient. This is the the same as doing SerializeAndFormat().&lt;/p&gt;

&lt;h2&gt;PrintDump&lt;/h2&gt;

&lt;p&gt;And do you remember this code?&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;csharp&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;csharp&quot; id=&quot;cb74245&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;var trees = http.&lt;span style=&quot;color: #0000FF;&quot;&gt;Get&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;http://localhost:65367/trees&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;foreach&lt;/span&gt; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;var t &lt;span style=&quot;color: #0600FF;&quot;&gt;in&lt;/span&gt; trees.&lt;span style=&quot;color: #0000FF;&quot;&gt;DynamicBody&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;Trees&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.&lt;span style=&quot;color: #0000FF;&quot;&gt;WriteLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;t.&lt;span style=&quot;color: #0000FF;&quot;&gt;Id&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.&lt;span style=&quot;color: #0000FF;&quot;&gt;WriteLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;t.&lt;span style=&quot;color: #0000FF;&quot;&gt;Genus&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #000000;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var result = http.&lt;span style=&quot;color: #0000FF;&quot;&gt;Get&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;http://localhost:65367/trees/1&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var tree = result.&lt;span style=&quot;color: #0000FF;&quot;&gt;DynamicBody&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.&lt;span style=&quot;color: #0000FF;&quot;&gt;WriteLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;tree.&lt;span style=&quot;color: #0000FF;&quot;&gt;Id&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.&lt;span style=&quot;color: #0000FF;&quot;&gt;WriteLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;tree.&lt;span style=&quot;color: #0000FF;&quot;&gt;Genus&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb97625&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Lots of Console.Writelines and not very robust.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;csharp&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;csharp&quot; id=&quot;cb45053&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;var trees = http.&lt;span style=&quot;color: #0000FF;&quot;&gt;Get&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;http://localhost:65367/trees&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; trees.&lt;span style=&quot;color: #0000FF;&quot;&gt;StaticBody&lt;/span&gt;&amp;lt;Object&amp;gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;PrintDump&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var result = http.&lt;span style=&quot;color: #0000FF;&quot;&gt;Get&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;http://localhost:65367/trees/1&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; result.&lt;span style=&quot;color: #0000FF;&quot;&gt;StaticBody&lt;/span&gt;&amp;lt;Object&amp;gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;PrintDump&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb96121&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;PrintDup won&#039;t work on dynamic objects so I switched to a staticobject, but easyhttp doesn&#039;t mind.&lt;/p&gt;

&lt;p&gt;And I get this as the result.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;{&lt;br /&gt;
        Trees:&lt;br /&gt;
        [&lt;br /&gt;
                {&lt;br /&gt;
                        Id: 1,&lt;br /&gt;
                        Genus: Fagus&lt;br /&gt;
                },&lt;br /&gt;
                {&lt;br /&gt;
                        Id: 2,&lt;br /&gt;
                        Genus: Quercus&lt;br /&gt;
                },&lt;br /&gt;
                {&lt;br /&gt;
                        Id: 3,&lt;br /&gt;
                        Genus: Betula&lt;br /&gt;
                },&lt;br /&gt;
                {&lt;br /&gt;
                        Id: 4,&lt;br /&gt;
                        Genus: Fagus&lt;br /&gt;
                },&lt;br /&gt;
                {&lt;br /&gt;
                        Id: 5,&lt;br /&gt;
                        Genus: Quercus&lt;br /&gt;
                },&lt;br /&gt;
                {&lt;br /&gt;
                        Id: 6,&lt;br /&gt;
                        Genus: Betula&lt;br /&gt;
                },&lt;br /&gt;
                {&lt;br /&gt;
                        Id: 7,&lt;br /&gt;
                        Genus: Fagus&lt;br /&gt;
                },&lt;br /&gt;
                {&lt;br /&gt;
                        Id: 8,&lt;br /&gt;
                        Genus: Quercus&lt;br /&gt;
                },&lt;br /&gt;
                {&lt;br /&gt;
                        Id: 9,&lt;br /&gt;
                        Genus: Betula&lt;br /&gt;
                },&lt;br /&gt;
                {&lt;br /&gt;
                        Id: 10,&lt;br /&gt;
                        Genus: Fagus&lt;br /&gt;
                },&lt;br /&gt;
                {&lt;br /&gt;
                        Id: 11,&lt;br /&gt;
                        Genus: Quercus&lt;br /&gt;
                },&lt;br /&gt;
                {&lt;br /&gt;
                        Id: 12,&lt;br /&gt;
                        Genus: Betula&lt;br /&gt;
                },&lt;br /&gt;
                {&lt;br /&gt;
                        Id: 13,&lt;br /&gt;
                        Genus: Fagus&lt;br /&gt;
                },&lt;br /&gt;
                {&lt;br /&gt;
                        Id: 14,&lt;br /&gt;
                        Genus: Quercus&lt;br /&gt;
                },&lt;br /&gt;
                {&lt;br /&gt;
                        Id: 15,&lt;br /&gt;
                        Genus: Betula&lt;br /&gt;
                }&lt;br /&gt;
        ],&lt;br /&gt;
        NumberOfTrees: 15&lt;br /&gt;
}&lt;br /&gt;
{&lt;br /&gt;
        Id: 1,&lt;br /&gt;
        Genus: Fagus&lt;br /&gt;
}&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Genius.&lt;/p&gt;

&lt;h2&gt;SerializeToString&lt;/h2&gt;

&lt;p&gt;And if you on&#039;t like the formatting then you can use SerializeToString().&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;csharp&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;csharp&quot; id=&quot;cb83228&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;var trees = http.&lt;span style=&quot;color: #0000FF;&quot;&gt;Get&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;http://localhost:65367/trees&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;Console.&lt;span style=&quot;color: #0000FF;&quot;&gt;WriteLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;trees.&lt;span style=&quot;color: #0000FF;&quot;&gt;StaticBody&lt;/span&gt;&amp;lt;Object&amp;gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;SerializeToString&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;var result = http.&lt;span style=&quot;color: #0000FF;&quot;&gt;Get&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #808080;&quot;&gt;&amp;quot;http://localhost:65367/trees/1&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;Console.&lt;span style=&quot;color: #0000FF;&quot;&gt;WriteLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;result.&lt;span style=&quot;color: #0000FF;&quot;&gt;StaticBody&lt;/span&gt;&amp;lt;Object&amp;gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #0000FF;&quot;&gt;SerializeToString&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb16544&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Which will have this kind of output.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;{&quot;Trees&quot;:[{&quot;Id&quot;:1,&quot;Genus&quot;:&quot;Fagus&quot;},{&quot;Id&quot;:2,&quot;Genus&quot;:&quot;Quercus&quot;},{&quot;Id&quot;:3,&quot;Genus&quot;:&quot;B&lt;br /&gt;
etula&quot;},{&quot;Id&quot;:4,&quot;Genus&quot;:&quot;Fagus&quot;},{&quot;Id&quot;:5,&quot;Genus&quot;:&quot;Quercus&quot;},{&quot;Id&quot;:6,&quot;Genus&quot;:&quot;Bet&lt;br /&gt;
ula&quot;},{&quot;Id&quot;:7,&quot;Genus&quot;:&quot;Fagus&quot;},{&quot;Id&quot;:8,&quot;Genus&quot;:&quot;Quercus&quot;},{&quot;Id&quot;:9,&quot;Genus&quot;:&quot;Betul&lt;br /&gt;
a&quot;},{&quot;Id&quot;:10,&quot;Genus&quot;:&quot;Fagus&quot;},{&quot;Id&quot;:11,&quot;Genus&quot;:&quot;Quercus&quot;},{&quot;Id&quot;:12,&quot;Genus&quot;:&quot;Betu&lt;br /&gt;
la&quot;},{&quot;Id&quot;:13,&quot;Genus&quot;:&quot;Fagus&quot;},{&quot;Id&quot;:14,&quot;Genus&quot;:&quot;Quercus&quot;},{&quot;Id&quot;:15,&quot;Genus&quot;:&quot;Bet&lt;br /&gt;
ula&quot;}],&quot;NumberOfTrees&quot;:15}&lt;br /&gt;
{&quot;Id&quot;:1,&quot;Genus&quot;:&quot;Fagus&quot;}&lt;/p&gt;&lt;/blockquote&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;These are methods that come in very handy when you do a spike or they would even come in handy for debugging, sometimes even in production.&lt;/p&gt;

&lt;p&gt;And there are even more extension methods in that little package. You can find them all &lt;a href=&quot;https://github.com/ServiceStack/ServiceStack.Text#readme&quot;&gt;on their github page&lt;/a&gt;. Just look at ToJson and ToXml.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DesktopDev/MSTech/servicestack-text-has-a-nice&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<h2>Introduction</h2>

<p>Yesterday I was <a href="http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/nancy-and-returning-a-pdf">adding a pdf feature to my Nancy service</a>. And I was outputting my objects to the pdf like this.</p>

<div class="codebox"><div class="codeheader"><span>csharp</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb67231'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb67231','cb35292'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="csharp" id="cb67231" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>var prop <span style="color: #0600FF;">in</span> model.<span style="color: #0000FF;">GetType</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">GetProperties</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2"><span style="color: #000000;">&#123;</span></li><li style="" class="li1">&nbsp; oDoc.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Paragraph<span style="color: #000000;">&#40;</span>prop.<span style="color: #0000FF;">Name</span> + <span style="color: #808080;">&quot;:&quot;</span> + prop.<span style="color: #0000FF;">GetValue</span><span style="color: #000000;">&#40;</span>model<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>; &nbsp; &nbsp;</li><li style="" class="li2"><span style="color: #000000;">&#125;</span></li></ol></div><div id="cb35292" style="display: none; color: red;"></div></div></div>

<p>But we all know this is far from finished and will only work in the most simple of cases, once you add complex types to your type the results will be less than optimal.</p>

<p>Of course you are not alone in this world and other people have had to do this to. And Demis Bellot even made a nuget package out of his solution. So here is Servicestack.Text and the <a href="http://www.servicestack.net/mythz_blog/?p=202">Dump </a>extension method and friends.</p>

<h2>Dump</h2>

<p>So go ahead and look for servicestack.text on nuget and add it to your project.</p>

<p>First of all I would like to change my method above to use the Dump() method.</p>

<p>And so my method now looks like this.</p>

<div class="codebox"><div class="codeheader"><span>chsarp</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb89771'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb89771','cb18661'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="chsarp" id="cb89771" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">protected virtual Action&lt;Stream&gt; GetPdfContents(TModel model)</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; {</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return stream =&gt;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var oDoc = new Document(PageSize.A4);</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PdfWriter.GetInstance(oDoc, stream);</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oDoc.Open();</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oDoc.Add(new Paragraph(model.Dump())); &nbsp; &nbsp;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oDoc.Close();</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; };</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; }</li></ol></div><div id="cb18661" style="display: none; color: red;"></div></div></div>

<p>So you just need you object and call the Dump() extension method on it and the output will look like this.</p>

<blockquote><p>{<br />
propertyname: value,<br />
propertyname2: value<br />
}</p></blockquote>

<p>Nicely formatted JSV.<br />
 <br />
Yep that's it.</p>

<p>The output now looks like this.</p>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/users/chrissie1/servicestacktext/servicestacktext1.png?mtime=1356945714"><img alt="" src="http://blogs.lessthandot.com/media/users/chrissie1/servicestacktext/servicestacktext1.png?mtime=1356945714" width="532" height="670" /></a></div>

<p>Or I could output a list of objects and that would look like this.</p>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/users/chrissie1/servicestacktext/servicestacktext2.png?mtime=1356945965"><img alt="" src="http://blogs.lessthandot.com/media/users/chrissie1/servicestacktext/servicestacktext2.png?mtime=1356945965" width="594" height="723" /></a></div>

<p>And that is very convenient. This is the the same as doing SerializeAndFormat().</p>

<h2>PrintDump</h2>

<p>And do you remember this code?</p>

<div class="codebox"><div class="codeheader"><span>csharp</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb12786'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb12786','cb4655'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="csharp" id="cb12786" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">var trees = http.<span style="color: #0000FF;">Get</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;http://localhost:65367/trees&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>var t <span style="color: #0600FF;">in</span> trees.<span style="color: #0000FF;">DynamicBody</span>.<span style="color: #0000FF;">Trees</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>t.<span style="color: #0000FF;">Id</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>t.<span style="color: #0000FF;">Genus</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var result = http.<span style="color: #0000FF;">Get</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;http://localhost:65367/trees/1&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var tree = result.<span style="color: #0000FF;">DynamicBody</span>;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>tree.<span style="color: #0000FF;">Id</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>tree.<span style="color: #0000FF;">Genus</span><span style="color: #000000;">&#41;</span>;</li></ol></div><div id="cb4655" style="display: none; color: red;"></div></div></div>

<p>Lots of Console.Writelines and not very robust.</p>

<div class="codebox"><div class="codeheader"><span>csharp</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb61372'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb61372','cb68428'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="csharp" id="cb61372" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">var trees = http.<span style="color: #0000FF;">Get</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;http://localhost:65367/trees&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; trees.<span style="color: #0000FF;">StaticBody</span>&lt;Object&gt;<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">PrintDump</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var result = http.<span style="color: #0000FF;">Get</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;http://localhost:65367/trees/1&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result.<span style="color: #0000FF;">StaticBody</span>&lt;Object&gt;<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">PrintDump</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</li></ol></div><div id="cb68428" style="display: none; color: red;"></div></div></div>

<p>PrintDup won't work on dynamic objects so I switched to a staticobject, but easyhttp doesn't mind.</p>

<p>And I get this as the result.</p>

<blockquote><p>{<br />
        Trees:<br />
        [<br />
                {<br />
                        Id: 1,<br />
                        Genus: Fagus<br />
                },<br />
                {<br />
                        Id: 2,<br />
                        Genus: Quercus<br />
                },<br />
                {<br />
                        Id: 3,<br />
                        Genus: Betula<br />
                },<br />
                {<br />
                        Id: 4,<br />
                        Genus: Fagus<br />
                },<br />
                {<br />
                        Id: 5,<br />
                        Genus: Quercus<br />
                },<br />
                {<br />
                        Id: 6,<br />
                        Genus: Betula<br />
                },<br />
                {<br />
                        Id: 7,<br />
                        Genus: Fagus<br />
                },<br />
                {<br />
                        Id: 8,<br />
                        Genus: Quercus<br />
                },<br />
                {<br />
                        Id: 9,<br />
                        Genus: Betula<br />
                },<br />
                {<br />
                        Id: 10,<br />
                        Genus: Fagus<br />
                },<br />
                {<br />
                        Id: 11,<br />
                        Genus: Quercus<br />
                },<br />
                {<br />
                        Id: 12,<br />
                        Genus: Betula<br />
                },<br />
                {<br />
                        Id: 13,<br />
                        Genus: Fagus<br />
                },<br />
                {<br />
                        Id: 14,<br />
                        Genus: Quercus<br />
                },<br />
                {<br />
                        Id: 15,<br />
                        Genus: Betula<br />
                }<br />
        ],<br />
        NumberOfTrees: 15<br />
}<br />
{<br />
        Id: 1,<br />
        Genus: Fagus<br />
}</p></blockquote>

<p>Genius.</p>

<h2>SerializeToString</h2>

<p>And if you on't like the formatting then you can use SerializeToString().</p>

<div class="codebox"><div class="codeheader"><span>csharp</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb31810'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb31810','cb94477'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="csharp" id="cb31810" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">var trees = http.<span style="color: #0000FF;">Get</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;http://localhost:65367/trees&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li2">Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>trees.<span style="color: #0000FF;">StaticBody</span>&lt;Object&gt;<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">SerializeToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li1">var result = http.<span style="color: #0000FF;">Get</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;http://localhost:65367/trees/1&quot;</span><span style="color: #000000;">&#41;</span>;</li><li style="" class="li2">Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>result.<span style="color: #0000FF;">StaticBody</span>&lt;Object&gt;<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">SerializeToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;</li></ol></div><div id="cb94477" style="display: none; color: red;"></div></div></div>

<p>Which will have this kind of output.</p>

<blockquote><p>{"Trees":[{"Id":1,"Genus":"Fagus"},{"Id":2,"Genus":"Quercus"},{"Id":3,"Genus":"B<br />
etula"},{"Id":4,"Genus":"Fagus"},{"Id":5,"Genus":"Quercus"},{"Id":6,"Genus":"Bet<br />
ula"},{"Id":7,"Genus":"Fagus"},{"Id":8,"Genus":"Quercus"},{"Id":9,"Genus":"Betul<br />
a"},{"Id":10,"Genus":"Fagus"},{"Id":11,"Genus":"Quercus"},{"Id":12,"Genus":"Betu<br />
la"},{"Id":13,"Genus":"Fagus"},{"Id":14,"Genus":"Quercus"},{"Id":15,"Genus":"Bet<br />
ula"}],"NumberOfTrees":15}<br />
{"Id":1,"Genus":"Fagus"}</p></blockquote>

<h2>Conclusion</h2>

<p>These are methods that come in very handy when you do a spike or they would even come in handy for debugging, sometimes even in production.</p>

<p>And there are even more extension methods in that little package. You can find them all <a href="https://github.com/ServiceStack/ServiceStack.Text#readme">on their github page</a>. Just look at ToJson and ToXml.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DesktopDev/MSTech/servicestack-text-has-a-nice">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DesktopDev/MSTech/servicestack-text-has-a-nice#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DesktopDev/?tempskin=_rss2&#38;disp=comments&#38;p=1999</wfw:commentRss>
		</item>
				<item>
			<title>Batch renaming files with powershell</title>
			<link>http://blogs.lessthandot.com/index.php/DesktopDev/MSTech/batch-renaming-files-with-powershell</link>
			<pubDate>Thu, 27 Dec 2012 15:13:00 +0000</pubDate>			<dc:creator>Christiaan Baes (chrissie1)</dc:creator>
			<category domain="main">Microsoft Technologies</category>			<guid isPermaLink="false">1996@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;I like powershell and from time to time I even use it.&lt;/p&gt;

&lt;p&gt;This time I needed to rename a lot of files in some directory I had.&lt;/p&gt;

&lt;p&gt;First thing to note is that these files are on a NAS.&lt;/p&gt;

&lt;p&gt;No problem just do&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;text&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;text&quot; id=&quot;cb59161&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;cd \\192.168.1.152\series&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb36224&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt; &lt;/p&gt;

&lt;p&gt;and you&#039;re on that drive.&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/users/chrissie1/powershell/powershellbatchrename2.png?mtime=1356627627&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/users/chrissie1/powershell/powershellbatchrename2.png?mtime=1356627627&quot; width=&quot;813&quot; height=&quot;252&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;That doesn&#039;t work with the normal commandline BTW.&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/users/chrissie1/powershell/powershellbatchrename1.png?mtime=1356627545&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/users/chrissie1/powershell/powershellbatchrename1.png?mtime=1356627545&quot; width=&quot;677&quot; height=&quot;343&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;So now we are there we can see we have bunch of files.&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/users/chrissie1/powershell/powershellbatchrename3.png?mtime=1356627807&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/users/chrissie1/powershell/powershellbatchrename3.png?mtime=1356627807&quot; width=&quot;580&quot; height=&quot;475&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;It is clear that these files don&#039;t say a lot about the contents, I will want to fix that. I want to prefix them all with Stargate. Easy just cd your way to that directory &lt;code class=&quot;codespan&quot;&gt;Stargate/SG1/Season 1&lt;/code&gt; and do this.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;text&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;text&quot; id=&quot;cb55913&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;Dir *.mkv | rename-item -newname { &amp;quot;Stargate &amp;quot; + $_.Name}&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb99236&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Yep that&#039;s one line of code.&lt;/p&gt;

&lt;p&gt;But darnit I have more than one season of Stargate, I have 10.&lt;/p&gt;

&lt;p&gt;Not to worry just go to the Stargate/SG1 directory instead and do this.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;text&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;text&quot; id=&quot;cb92053&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;Get-ChildItem -recurse | Where {$_ -IS [IO.FileInfo]} | rename-item -newname { &amp;quot;Stargate &amp;quot; + $_.Name}&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb12721&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And done. Oh no, I made a misstake I also have Atlantis and Universe on there so I would better name them Stargate - SG1.&lt;/p&gt;

&lt;p&gt;Not to worry I can just replace what I did before. Like this.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;text&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;text&quot; id=&quot;cb74632&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;Get-ChildItem -recurse | Where {$_ -IS [IO.FileInfo]} | rename-item -newname { -replace &amp;quot;Stargate &amp;quot;,&amp;quot;Stargate - SG1 &amp;quot; }&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb94844&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And I&#039;m done. Now to just do this for the 2 others and everything is a lot clearer from now on.&lt;/p&gt;

&lt;p&gt;Happy powershelling people.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DesktopDev/MSTech/batch-renaming-files-with-powershell&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>I like powershell and from time to time I even use it.</p>

<p>This time I needed to rename a lot of files in some directory I had.</p>

<p>First thing to note is that these files are on a NAS.</p>

<p>No problem just do</p>

<div class="codebox"><div class="codeheader"><span>text</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb11725'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb11725','cb97765'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="text" id="cb11725" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">cd \\192.168.1.152\series</li></ol></div><div id="cb97765" style="display: none; color: red;"></div></div></div><p> </p>

<p>and you're on that drive.</p>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/users/chrissie1/powershell/powershellbatchrename2.png?mtime=1356627627"><img alt="" src="http://blogs.lessthandot.com/media/users/chrissie1/powershell/powershellbatchrename2.png?mtime=1356627627" width="813" height="252" /></a></div>

<p>That doesn't work with the normal commandline BTW.</p>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/users/chrissie1/powershell/powershellbatchrename1.png?mtime=1356627545"><img alt="" src="http://blogs.lessthandot.com/media/users/chrissie1/powershell/powershellbatchrename1.png?mtime=1356627545" width="677" height="343" /></a></div>

<p>So now we are there we can see we have bunch of files.</p>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/users/chrissie1/powershell/powershellbatchrename3.png?mtime=1356627807"><img alt="" src="http://blogs.lessthandot.com/media/users/chrissie1/powershell/powershellbatchrename3.png?mtime=1356627807" width="580" height="475" /></a></div>

<p>It is clear that these files don't say a lot about the contents, I will want to fix that. I want to prefix them all with Stargate. Easy just cd your way to that directory <code class="codespan">Stargate/SG1/Season 1</code> and do this.</p>

<div class="codebox"><div class="codeheader"><span>text</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb76191'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb76191','cb25908'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="text" id="cb76191" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">Dir *.mkv | rename-item -newname { &quot;Stargate &quot; + $_.Name}</li></ol></div><div id="cb25908" style="display: none; color: red;"></div></div></div>

<p>Yep that's one line of code.</p>

<p>But darnit I have more than one season of Stargate, I have 10.</p>

<p>Not to worry just go to the Stargate/SG1 directory instead and do this.</p>

<div class="codebox"><div class="codeheader"><span>text</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb38895'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb38895','cb53049'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="text" id="cb38895" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">Get-ChildItem -recurse | Where {$_ -IS [IO.FileInfo]} | rename-item -newname { &quot;Stargate &quot; + $_.Name}</li></ol></div><div id="cb53049" style="display: none; color: red;"></div></div></div>

<p>And done. Oh no, I made a misstake I also have Atlantis and Universe on there so I would better name them Stargate - SG1.</p>

<p>Not to worry I can just replace what I did before. Like this.</p>

<div class="codebox"><div class="codeheader"><span>text</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb93115'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb93115','cb24019'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="text" id="cb93115" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">Get-ChildItem -recurse | Where {$_ -IS [IO.FileInfo]} | rename-item -newname { -replace &quot;Stargate &quot;,&quot;Stargate - SG1 &quot; }</li></ol></div><div id="cb24019" style="display: none; color: red;"></div></div></div>

<p>And I'm done. Now to just do this for the 2 others and everything is a lot clearer from now on.</p>

<p>Happy powershelling people.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DesktopDev/MSTech/batch-renaming-files-with-powershell">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DesktopDev/MSTech/batch-renaming-files-with-powershell#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DesktopDev/?tempskin=_rss2&#38;disp=comments&#38;p=1996</wfw:commentRss>
		</item>
				<item>
			<title>Smalltalk</title>
			<link>http://blogs.lessthandot.com/index.php/DesktopDev/GeneralPurposeLanguages/smalltalk</link>
			<pubDate>Sat, 08 Dec 2012 06:24:00 +0000</pubDate>			<dc:creator>Christiaan Baes (chrissie1)</dc:creator>
			<category domain="main">General Purpose Languages</category>			<guid isPermaLink="false">1941@http://blogs.lessthandot.com/</guid>
						<description>&lt;h2&gt;Introduction&lt;/h2&gt;

&lt;p&gt;A few days ago &lt;a href=&quot;https://twitter.com/demisbellot&quot;&gt;Demis Bellot&lt;/a&gt; (the creator of Servicestack) was talking about &lt;a href=&quot;http://en.wikipedia.org/wiki/Smalltalk&quot;&gt;Smalltalk &lt;/a&gt;on twitter. A little discussion came about involving &lt;a href=&quot;http://blogs.lessthandot.com/index.php/All/?disp=authdir&amp;amp;author=5&quot;&gt;Alex Ullrich&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/users/chrissie1/smalltalk/smalltalk1.png?mtime=1354953430&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/users/chrissie1/smalltalk/smalltalk1.png?mtime=1354953430&quot; width=&quot;299&quot; height=&quot;718&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;So my next mission was to learn a thing or two about smalltalk myself. &lt;/p&gt;

&lt;h2&gt;Installation&lt;/h2&gt;

&lt;p&gt;I tried two smalltalk IDE&#039;s. &lt;a href=&quot;http://en.wikipedia.org/wiki/Squeak&quot;&gt;Squeak&lt;/a&gt; (which I couldn&#039;t get to work on Win8) and &lt;a href=&quot;http://www.object-arts.com/&quot;&gt;Dolphin X6 community edition&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So I stuck with Dolphin. And the installation is next, next, next and finish.&lt;/p&gt;

&lt;h2&gt;The beginning&lt;/h2&gt;

&lt;p&gt;So how does one learn Smalltalk, on starts with finding a good tutorial. And I found a very good one by Bitwise magazine. &lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.bitwisemag.com/copy/programming/smalltalk/smalltalk1.html&quot;&gt;Lesson 1&lt;/a&gt; has Dolphin and Squeak in it but from &lt;a href=&quot;http://www.bitwisemag.com/copy/programming/smalltalk/dolphintutorial.html&quot;&gt;Lesson 2&lt;/a&gt; you can go to a dedicated Dolphin page(s).&lt;/p&gt;

&lt;p&gt;Just follow that tutorial and you will be fine. &lt;/p&gt;

&lt;p&gt;To be honest, smalltalk is weird. I have done a few languages in my time, lots of basic dialects (visual basic, turbobasic VBA, ...), lots of c dialects (C++, Java, C#, javascript, PHP, ...), COBOL, Delphi, and some I have forgotten what the syntax looks like. Smalltalk however is nothing like the previous languages. &lt;/p&gt;

&lt;p&gt;It uses the comma to concatenate strings.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;smalltalk&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;smalltalk&quot; id=&quot;cb25057&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #7f0000;&quot;&gt;&#039;Hello&#039;&lt;/span&gt;,&lt;span style=&quot;color: #7f0000;&quot;&gt;&#039; World!&#039;&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb27552&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;It uses the dot as a line-ending character.&lt;/p&gt;

&lt;p&gt;It uses square brackets for blocks of code.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;smalltalk&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;smalltalk&quot; id=&quot;cb3203&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #7f0000;&quot;&gt;1&lt;/span&gt; timesRepeat: &lt;span style=&quot;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;Transcript&lt;/span&gt; clear.&lt;br /&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;Transcript&lt;/span&gt; show: &lt;span style=&quot;color: #7f0000;&quot;&gt;&#039;Hello&#039;&lt;/span&gt;; cr.&lt;br /&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;Transcript&lt;/span&gt; show: &lt;span style=&quot;color: #7f0000;&quot;&gt;&#039;Hello2&#039;&lt;/span&gt;; cr.&lt;span style=&quot;&quot;&gt;&amp;#93;&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb58674&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;It uses the space as a seperator character to define arrays.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;smalltalk&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;smalltalk&quot; id=&quot;cb84312&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #00007f;&quot;&gt;mixedlist&lt;/span&gt; := #&lt;span style=&quot;&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span style=&quot;color: #7f0000;&quot;&gt;&#039;one&#039;&lt;/span&gt; &lt;span style=&quot;color: #7f0000;&quot;&gt;2&lt;/span&gt; &lt;span style=&quot;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #00007f;&quot;&gt;&lt;span style=&quot;color: #7f0000;&quot;&gt;3&lt;/span&gt;&lt;/span&gt; &lt;span style=&quot;color: #7f0000;&quot;&gt;4&lt;/span&gt; &lt;span style=&quot;color: #7f0000;&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;&quot;&gt;&amp;#41;&lt;/span&gt; $&lt;span style=&quot;color: #7f0000;&quot;&gt;6&lt;/span&gt; &lt;span style=&quot;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb59535&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;It uses capitalization to determine scope, variables starting with an uppercase letter are Global scope, variables with a lowercase are local to your workspace.&lt;/p&gt;

&lt;p&gt;And there are many more things you will discover. &lt;/p&gt;

&lt;p&gt;Learning something like smalltalk is really cool. It opens your eyes a bit. &lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;Go ahead, download dolphin and follow the bitwise tutorial, you will learn something new if you have never tried smalltalk before.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DesktopDev/GeneralPurposeLanguages/smalltalk&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<h2>Introduction</h2>

<p>A few days ago <a href="https://twitter.com/demisbellot">Demis Bellot</a> (the creator of Servicestack) was talking about <a href="http://en.wikipedia.org/wiki/Smalltalk">Smalltalk </a>on twitter. A little discussion came about involving <a href="http://blogs.lessthandot.com/index.php/All/?disp=authdir&amp;author=5">Alex Ullrich</a>.</p>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/users/chrissie1/smalltalk/smalltalk1.png?mtime=1354953430"><img alt="" src="http://blogs.lessthandot.com/media/users/chrissie1/smalltalk/smalltalk1.png?mtime=1354953430" width="299" height="718" /></a></div>

<p>So my next mission was to learn a thing or two about smalltalk myself. </p>

<h2>Installation</h2>

<p>I tried two smalltalk IDE's. <a href="http://en.wikipedia.org/wiki/Squeak">Squeak</a> (which I couldn't get to work on Win8) and <a href="http://www.object-arts.com/">Dolphin X6 community edition</a>.</p>

<p>So I stuck with Dolphin. And the installation is next, next, next and finish.</p>

<h2>The beginning</h2>

<p>So how does one learn Smalltalk, on starts with finding a good tutorial. And I found a very good one by Bitwise magazine. </p>

<p><a href="http://www.bitwisemag.com/copy/programming/smalltalk/smalltalk1.html">Lesson 1</a> has Dolphin and Squeak in it but from <a href="http://www.bitwisemag.com/copy/programming/smalltalk/dolphintutorial.html">Lesson 2</a> you can go to a dedicated Dolphin page(s).</p>

<p>Just follow that tutorial and you will be fine. </p>

<p>To be honest, smalltalk is weird. I have done a few languages in my time, lots of basic dialects (visual basic, turbobasic VBA, ...), lots of c dialects (C++, Java, C#, javascript, PHP, ...), COBOL, Delphi, and some I have forgotten what the syntax looks like. Smalltalk however is nothing like the previous languages. </p>

<p>It uses the comma to concatenate strings.</p>

<div class="codebox"><div class="codeheader"><span>smalltalk</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb57987'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb57987','cb93791'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="smalltalk" id="cb57987" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #7f0000;">'Hello'</span>,<span style="color: #7f0000;">' World!'</span>.</li></ol></div><div id="cb93791" style="display: none; color: red;"></div></div></div>

<p>It uses the dot as a line-ending character.</p>

<p>It uses square brackets for blocks of code.</p>

<div class="codebox"><div class="codeheader"><span>smalltalk</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb72197'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb72197','cb87994'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="smalltalk" id="cb72197" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #7f0000;">1</span> timesRepeat: <span style="">&#91;</span><span style="color: #0000ff;">Transcript</span> clear.</li><li style="" class="li2"><span style="color: #0000ff;">Transcript</span> show: <span style="color: #7f0000;">'Hello'</span>; cr.</li><li style="" class="li1"><span style="color: #0000ff;">Transcript</span> show: <span style="color: #7f0000;">'Hello2'</span>; cr.<span style="">&#93;</span>.</li></ol></div><div id="cb87994" style="display: none; color: red;"></div></div></div>

<p>It uses the space as a seperator character to define arrays.</p>

<div class="codebox"><div class="codeheader"><span>smalltalk</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb28261'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb28261','cb8486'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="smalltalk" id="cb28261" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #00007f;">mixedlist</span> := #<span style="">&#40;</span> <span style="color: #7f0000;">'one'</span> <span style="color: #7f0000;">2</span> <span style="">&#40;</span><span style="color: #00007f;"><span style="color: #7f0000;">3</span></span> <span style="color: #7f0000;">4</span> <span style="color: #7f0000;">5</span><span style="">&#41;</span> $<span style="color: #7f0000;">6</span> <span style="">&#41;</span>.</li></ol></div><div id="cb8486" style="display: none; color: red;"></div></div></div>

<p>It uses capitalization to determine scope, variables starting with an uppercase letter are Global scope, variables with a lowercase are local to your workspace.</p>

<p>And there are many more things you will discover. </p>

<p>Learning something like smalltalk is really cool. It opens your eyes a bit. </p>

<h2>Conclusion</h2>

<p>Go ahead, download dolphin and follow the bitwise tutorial, you will learn something new if you have never tried smalltalk before.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DesktopDev/GeneralPurposeLanguages/smalltalk">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DesktopDev/GeneralPurposeLanguages/smalltalk#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DesktopDev/?tempskin=_rss2&#38;disp=comments&#38;p=1941</wfw:commentRss>
		</item>
				<item>
			<title>Kotlin and Maven</title>
			<link>http://blogs.lessthandot.com/index.php/DesktopDev/SunTech/Java/kotlin-and-maven</link>
			<pubDate>Mon, 03 Dec 2012 09:54:00 +0000</pubDate>			<dc:creator>Christiaan Baes (chrissie1)</dc:creator>
			<category domain="main">Java</category>			<guid isPermaLink="false">1927@http://blogs.lessthandot.com/</guid>
						<description>&lt;h2&gt;Introduction&lt;/h2&gt;

&lt;p&gt;Last week I asked if &lt;a href=&quot;https://github.com/hhariri/spek&quot;&gt;Spek &lt;/a&gt;was on a Maven repository so I could easily add it to my project and test it. &lt;br /&gt;
Someone who will remain anonymous (who still needs to wash my car) and runs the Spek project told me it wasn&#039;t and that I could be so nice to add it.&lt;/p&gt;

&lt;p&gt;I know next to nothing about Maven, except that it exists. So I went on the Google and found... a lot of things that I didn&#039;t know about. But in the end &lt;a href=&quot;http://confluence.jetbrains.net/display/Kotlin/Kotlin+Build+Tools#KotlinBuildTools-Maven&quot;&gt;I found this&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;And that helped just a little. &lt;/p&gt;

&lt;h2&gt;Setting up Maven&lt;/h2&gt;

&lt;p&gt;Apparently everybody knows how to set up Maven but forget to tell how it is done. &lt;br /&gt;
So first of all I downloaded Maven 3.0.4 and then unzipped that in the Program files folder (x86). Then I had to add this &lt;code class=&quot;codespan&quot;&gt;E:\Program Files (x86)\apache-maven-3.0.4\bin&lt;/code&gt; to my Path in the System Variables whiyou can find in Control Panel -&gt; System -&gt; Advanced settings -&gt; Environment variables. I also needed to add the system variable JAVA_HOME and set it to this &lt;code class=&quot;codespan&quot;&gt;E:\Program Files (x86)\Java\jdk1.7.0\jre&lt;/code&gt; or the path to your jre of your JDK. &lt;/p&gt;

&lt;p&gt;You can also add the system variable M2_HOME and set it to this &lt;code class=&quot;codespan&quot;&gt;E:\Program Files (x86)\apache-maven-3.0.4&lt;/code&gt; or not. You can choose to add it manually to your module too.&lt;/p&gt;

&lt;p&gt;If you get this error&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;Error running kotlindeom [test]: No valid Maven installation found. Either set the home directory in the configuration dialog or set the M2_HOME environment variable on your system.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;then the above did not work. In Intellij go to File -&gt; Settings -&gt; Maven and copy the Maven directory in the Maven home directory field.&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlinandmaven1.png?mtime=1354533891&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlinandmaven1.png?mtime=1354533891&quot; width=&quot;981&quot; height=&quot;497&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;And now Maven works with Intellij 12. Oh joy.&lt;/p&gt;

&lt;h2&gt;MavenModule&lt;/h2&gt;

&lt;p&gt;It is now time to make our project.&lt;/p&gt;

&lt;p&gt;Make a new project and make it a Maven module.&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlinandmaven2.png?mtime=1354534102&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlinandmaven2.png?mtime=1354534102&quot; width=&quot;594&quot; height=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;use the quickstart archetype, or any other archetype since we are not going to use it anyway.&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlinandmaven3.png?mtime=1354534163&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlinandmaven3.png?mtime=1354534163&quot; width=&quot;594&quot; height=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;override the maven home directory if you did not set M2_HOME or if you so desire.&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlinandmaven4.png?mtime=1354534303&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlinandmaven4.png?mtime=1354534303&quot; width=&quot;594&quot; height=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;Now we can change the pom.xml file to this.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;xml&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;xml&quot; id=&quot;cb22863&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&lt;span style=&quot;font-weight: bold; color: black;&quot;&gt;&amp;lt;project&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;xmlns&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;http://maven.apache.org/POM/4.0.0&amp;quot;&lt;/span&gt; &lt;span style=&quot;color: #000066;&quot;&gt;xmlns:xsi&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;http://www.w3.org/2001/XMLSchema-instance&amp;quot;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &lt;span style=&quot;color: #000066;&quot;&gt;xsi:schemaLocation&lt;/span&gt;=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;http://maven.apache.org/POM/4.0.0 &amp;lt;a href=&amp;quot;&lt;/span&gt;http://maven.apache.org/xsd/maven&lt;span style=&quot;color: #cc66cc;&quot;&gt;-4.0&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;.0&lt;/span&gt;.xsd&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;&amp;gt;&lt;/span&gt;&amp;quot;&amp;gt;http://maven.apache.org/xsd/maven-4.0.0.xsd&amp;quot;&amp;gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;modelVersion&amp;gt;&lt;/span&gt;4.0.0&lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/modelVersion&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;kotlindemos&lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;kotlindeom&lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;version&amp;gt;&lt;/span&gt;1.0-SNAPSHOT&lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;properties&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;kotlin.version&amp;gt;&lt;/span&gt;0.1-SNAPSHOT&lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/kotlin.version&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;junit.version&amp;gt;&lt;/span&gt;4.11&lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/junit.version&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;project.build.sourceEncoding&amp;gt;&lt;/span&gt;UTF-8&lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/project.build.sourceEncoding&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/properties&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;dependencies&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.jetbrains.kotlin&lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;kotlin-stdlib&lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;version&amp;gt;&lt;/span&gt;${kotlin.version}&lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;junit&lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;junit&lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;version&amp;gt;&lt;/span&gt;${junit.version}&lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;scope&amp;gt;&lt;/span&gt;test&lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/scope&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/dependencies&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;build&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;sourceDirectory&amp;gt;&lt;/span&gt;${project.basedir}/src/main&lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/sourceDirectory&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;testSourceDirectory&amp;gt;&lt;/span&gt;${project.basedir}/src/test&lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/testSourceDirectory&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;plugins&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;plugin&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;kotlin-maven-plugin&lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.jetbrains.kotlin&lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;version&amp;gt;&lt;/span&gt;${kotlin.version}&lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;configuration/&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;executions&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;execution&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;id&amp;gt;&lt;/span&gt;compile&lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/id&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;phase&amp;gt;&lt;/span&gt;compile&lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/phase&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;goals&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;goal&amp;gt;&lt;/span&gt;compile&lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/goal&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/goals&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/execution&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;execution&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;id&amp;gt;&lt;/span&gt;test-compile&lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/id&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;phase&amp;gt;&lt;/span&gt;test-compile&lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/phase&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;goals&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;goal&amp;gt;&lt;/span&gt;test-compile&lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/goal&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/goals&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/execution&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/executions&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/plugin&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/plugins&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/build&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;repositories&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;repository&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;id&amp;gt;&lt;/span&gt;jetbrains-all&lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/id&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;url&amp;gt;&lt;/span&gt;http://repository.jetbrains.com/all&lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/url&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/repository&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/repositories&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;pluginRepositories&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;pluginRepository&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;id&amp;gt;&lt;/span&gt;jetbrains-all&lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/id&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;url&amp;gt;&lt;/span&gt;http://repository.jetbrains.com/all&lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/url&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/pluginRepository&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/pluginRepositories&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #009900;&quot;&gt;&amp;lt;/project&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb24600&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If everything is well you should not see any red in there.&lt;/p&gt;

&lt;h2&gt;Does it work?&lt;/h2&gt;

&lt;p&gt;Now we can start adding our kotlin files in.&lt;/p&gt;

&lt;p&gt;Create a package kotlin.kotlindemo in the main and remove the package java. Add a kotlin file to that and use this code.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;java&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;java&quot; id=&quot;cb40489&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;package&lt;/span&gt; demo&lt;br /&gt;&amp;nbsp;&lt;br /&gt;data &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; MyClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;val i : Int, val s : &lt;a href=&quot;http://www.google.com/search?hl=en&amp;amp;q=allinurl%3AString+java.sun.com&amp;amp;btnI=I%27m%20Feeling%20Lucky&quot;&gt;&lt;span style=&quot;color: #aaaadd; font-weight: bold;&quot;&gt;String&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb89639&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now add a kotlin.kotlindemo package to the test folder and add a kotlin file.&lt;/p&gt;

&lt;p&gt;With this code.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;java&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;java&quot; id=&quot;cb70392&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;package&lt;/span&gt; demo.&lt;span style=&quot;color: #006600;&quot;&gt;test&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #a1a100;&quot;&gt;import demo.MyClass&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #a1a100;&quot;&gt;import kotlin.test.assertEquals&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #a1a100;&quot;&gt;import org.junit.Test as test&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #a1a100;&quot;&gt;import kotlin.test.assertTrue&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #a1a100;&quot;&gt;import kotlin.test.assertFalse&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; TestMyClass&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; test fun IfPropertyIIsSetCorrectly&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; val c1 = MyClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;t&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; assertEquals&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;,c1.&lt;span style=&quot;color: #006600;&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; test fun IfPropertySIsSetCorrectly&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; val c1 = MyClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;t&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; assertEquals&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;t&amp;quot;&lt;/span&gt;,c1.&lt;span style=&quot;color: #006600;&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; test fun If2MyClassesWithTheSamePropertiesAreEqual&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; val c1 = MyClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;t&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; val c2 = MyClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;t&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; assertTrue&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;c1.&lt;span style=&quot;color: #006600;&quot;&gt;equals&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;c2&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; test fun If2MyClassesWithDifferentPropertiesAreNotEqual&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; val c1 = MyClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;t&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; val c2 = MyClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt;,&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;t&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; assertFalse&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;c1.&lt;span style=&quot;color: #006600;&quot;&gt;equals&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;c2&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; test fun IfToStringReturnsTheCorrectString&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; val c1 = MyClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;t&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; assertEquals&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;MyClass(i=1, s=t)&amp;quot;&lt;/span&gt;,c1.&lt;span style=&quot;color: #006600;&quot;&gt;toString&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb72152&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You might think this is the same class as in my previous blogpost but it isn&#039;t. My previous class was called testMyClass and by convention Maven only finds Test*, *Test or TestCase* classes. I found that out the hard way. Lucky me.&lt;/p&gt;

&lt;p&gt;Anyway, your project should look like this.&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlinandmaven5.png?mtime=1354535218&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlinandmaven5.png?mtime=1354535218&quot; width=&quot;387&quot; height=&quot;348&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;And now when we open our Maven project view. we should see this.&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlinandmaven6.png?mtime=1354535357&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlinandmaven6.png?mtime=1354535357&quot; width=&quot;465&quot; height=&quot;528&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;you can now doubleclick on test and see the magic happen.&lt;/p&gt;

&lt;p&gt;This should be the result.&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlinandmaven7.png?mtime=1354535495&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlinandmaven7.png?mtime=1354535495&quot; width=&quot;742&quot; height=&quot;313&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;5 tests run and none faild. Woohoo.&lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;It took me a while to get it to work since I could not find Maven and IntelliJ for dummies and the Maven site is full of XML. But it works and I&#039;m happy. Now on to Spek and getting the package into a repo, be afraid, be very afraid.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DesktopDev/SunTech/Java/kotlin-and-maven&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<h2>Introduction</h2>

<p>Last week I asked if <a href="https://github.com/hhariri/spek">Spek </a>was on a Maven repository so I could easily add it to my project and test it. <br />
Someone who will remain anonymous (who still needs to wash my car) and runs the Spek project told me it wasn't and that I could be so nice to add it.</p>

<p>I know next to nothing about Maven, except that it exists. So I went on the Google and found... a lot of things that I didn't know about. But in the end <a href="http://confluence.jetbrains.net/display/Kotlin/Kotlin+Build+Tools#KotlinBuildTools-Maven">I found this</a>. </p>

<p>And that helped just a little. </p>

<h2>Setting up Maven</h2>

<p>Apparently everybody knows how to set up Maven but forget to tell how it is done. <br />
So first of all I downloaded Maven 3.0.4 and then unzipped that in the Program files folder (x86). Then I had to add this <code class="codespan">E:\Program Files (x86)\apache-maven-3.0.4\bin</code> to my Path in the System Variables whiyou can find in Control Panel -> System -> Advanced settings -> Environment variables. I also needed to add the system variable JAVA_HOME and set it to this <code class="codespan">E:\Program Files (x86)\Java\jdk1.7.0\jre</code> or the path to your jre of your JDK. </p>

<p>You can also add the system variable M2_HOME and set it to this <code class="codespan">E:\Program Files (x86)\apache-maven-3.0.4</code> or not. You can choose to add it manually to your module too.</p>

<p>If you get this error</p>

<blockquote><p>Error running kotlindeom [test]: No valid Maven installation found. Either set the home directory in the configuration dialog or set the M2_HOME environment variable on your system.</p></blockquote>

<p>then the above did not work. In Intellij go to File -> Settings -> Maven and copy the Maven directory in the Maven home directory field.</p>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlinandmaven1.png?mtime=1354533891"><img alt="" src="http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlinandmaven1.png?mtime=1354533891" width="981" height="497" /></a></div>

<p>And now Maven works with Intellij 12. Oh joy.</p>

<h2>MavenModule</h2>

<p>It is now time to make our project.</p>

<p>Make a new project and make it a Maven module.</p>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlinandmaven2.png?mtime=1354534102"><img alt="" src="http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlinandmaven2.png?mtime=1354534102" width="594" height="640" /></a></div>

<p>use the quickstart archetype, or any other archetype since we are not going to use it anyway.</p>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlinandmaven3.png?mtime=1354534163"><img alt="" src="http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlinandmaven3.png?mtime=1354534163" width="594" height="640" /></a></div>

<p>override the maven home directory if you did not set M2_HOME or if you so desire.</p>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlinandmaven4.png?mtime=1354534303"><img alt="" src="http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlinandmaven4.png?mtime=1354534303" width="594" height="640" /></a></div>

<p>Now we can change the pom.xml file to this.</p>

<div class="codebox"><div class="codeheader"><span>xml</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb14497'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb14497','cb58728'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="xml" id="cb14497" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;project</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://maven.apache.org/POM/4.0.0&quot;</span> <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></li><li style="" class="li2">&nbsp; <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://maven.apache.org/POM/4.0.0 &lt;a href=&quot;</span>http://maven.apache.org/xsd/maven<span style="color: #cc66cc;">-4.0</span><span style="color: #cc66cc;">.0</span>.xsd<span style="color: #ff0000;">&quot;&gt;</span>&quot;&gt;http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;<span style="color: #009900;">&lt;/a&gt;</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #009900;">&lt;modelVersion&gt;</span>4.0.0<span style="color: #009900;">&lt;/modelVersion&gt;</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #009900;">&lt;groupId&gt;</span>kotlindemos<span style="color: #009900;">&lt;/groupId&gt;</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #009900;">&lt;artifactId&gt;</span>kotlindeom<span style="color: #009900;">&lt;/artifactId&gt;</span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #009900;">&lt;version&gt;</span>1.0-SNAPSHOT<span style="color: #009900;">&lt;/version&gt;</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #009900;">&lt;properties&gt;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;kotlin.version&gt;</span>0.1-SNAPSHOT<span style="color: #009900;">&lt;/kotlin.version&gt;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;junit.version&gt;</span>4.11<span style="color: #009900;">&lt;/junit.version&gt;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;project.build.sourceEncoding&gt;</span>UTF-8<span style="color: #009900;">&lt;/project.build.sourceEncoding&gt;</span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #009900;">&lt;/properties&gt;</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #009900;">&lt;dependencies&gt;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;dependency&gt;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;groupId&gt;</span>org.jetbrains.kotlin<span style="color: #009900;">&lt;/groupId&gt;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;artifactId&gt;</span>kotlin-stdlib<span style="color: #009900;">&lt;/artifactId&gt;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;version&gt;</span>${kotlin.version}<span style="color: #009900;">&lt;/version&gt;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;/dependency&gt;</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;dependency&gt;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;groupId&gt;</span>junit<span style="color: #009900;">&lt;/groupId&gt;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;artifactId&gt;</span>junit<span style="color: #009900;">&lt;/artifactId&gt;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;version&gt;</span>${junit.version}<span style="color: #009900;">&lt;/version&gt;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;scope&gt;</span>test<span style="color: #009900;">&lt;/scope&gt;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;/dependency&gt;</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #009900;">&lt;/dependencies&gt;</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #009900;">&lt;build&gt;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;sourceDirectory&gt;</span>${project.basedir}/src/main<span style="color: #009900;">&lt;/sourceDirectory&gt;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;testSourceDirectory&gt;</span>${project.basedir}/src/test<span style="color: #009900;">&lt;/testSourceDirectory&gt;</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;plugins&gt;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;plugin&gt;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;artifactId&gt;</span>kotlin-maven-plugin<span style="color: #009900;">&lt;/artifactId&gt;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;groupId&gt;</span>org.jetbrains.kotlin<span style="color: #009900;">&lt;/groupId&gt;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;version&gt;</span>${kotlin.version}<span style="color: #009900;">&lt;/version&gt;</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;configuration/&gt;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;executions&gt;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;execution&gt;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;id&gt;</span>compile<span style="color: #009900;">&lt;/id&gt;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;phase&gt;</span>compile<span style="color: #009900;">&lt;/phase&gt;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;goals&gt;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;goal&gt;</span>compile<span style="color: #009900;">&lt;/goal&gt;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;/goals&gt;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;/execution&gt;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;execution&gt;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;id&gt;</span>test-compile<span style="color: #009900;">&lt;/id&gt;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;phase&gt;</span>test-compile<span style="color: #009900;">&lt;/phase&gt;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;goals&gt;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;goal&gt;</span>test-compile<span style="color: #009900;">&lt;/goal&gt;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;/goals&gt;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;/execution&gt;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;/executions&gt;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;/plugin&gt;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;/plugins&gt;</span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #009900;">&lt;/build&gt;</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #009900;">&lt;repositories&gt;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;repository&gt;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;id&gt;</span>jetbrains-all<span style="color: #009900;">&lt;/id&gt;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;url&gt;</span>http://repository.jetbrains.com/all<span style="color: #009900;">&lt;/url&gt;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;/repository&gt;</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #009900;">&lt;/repositories&gt;</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #009900;">&lt;pluginRepositories&gt;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;pluginRepository&gt;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;id&gt;</span>jetbrains-all<span style="color: #009900;">&lt;/id&gt;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;url&gt;</span>http://repository.jetbrains.com/all<span style="color: #009900;">&lt;/url&gt;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;/pluginRepository&gt;</span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #009900;">&lt;/pluginRepositories&gt;</span></li><li style="" class="li1"><span style="color: #009900;">&lt;/project&gt;</span></span></li></ol></div><div id="cb58728" style="display: none; color: red;"></div></div></div>

<p>If everything is well you should not see any red in there.</p>

<h2>Does it work?</h2>

<p>Now we can start adding our kotlin files in.</p>

<p>Create a package kotlin.kotlindemo in the main and remove the package java. Add a kotlin file to that and use this code.</p>

<div class="codebox"><div class="codeheader"><span>java</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb40720'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb40720','cb97885'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="java" id="cb40720" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #000000; font-weight: bold;">package</span> demo</li><li style="" class="li2">&nbsp;</li><li style="" class="li1">data <span style="color: #000000; font-weight: bold;">class</span> MyClass<span style="color: #66cc66;">&#40;</span>val i : Int, val s : <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">String</span></a><span style="color: #66cc66;">&#41;</span></li></ol></div><div id="cb97885" style="display: none; color: red;"></div></div></div>

<p>Now add a kotlin.kotlindemo package to the test folder and add a kotlin file.</p>

<p>With this code.</p>

<div class="codebox"><div class="codeheader"><span>java</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb68553'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb68553','cb1937'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="java" id="cb68553" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #000000; font-weight: bold;">package</span> demo.<span style="color: #006600;">test</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #a1a100;">import demo.MyClass</span></li><li style="" class="li2"><span style="color: #a1a100;">import kotlin.test.assertEquals</span></li><li style="" class="li1"><span style="color: #a1a100;">import org.junit.Test as test</span></li><li style="" class="li2"><span style="color: #a1a100;">import kotlin.test.assertTrue</span></li><li style="" class="li1"><span style="color: #a1a100;">import kotlin.test.assertFalse</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> TestMyClass</li><li style="" class="li2"><span style="color: #66cc66;">&#123;</span></li><li style="" class="li1">&nbsp; &nbsp; test fun IfPropertyIIsSetCorrectly<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; val c1 = MyClass<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #ff0000;">&quot;t&quot;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; assertEquals<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,c1.<span style="color: #006600;">i</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; test fun IfPropertySIsSetCorrectly<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; val c1 = MyClass<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #ff0000;">&quot;t&quot;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; assertEquals<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;t&quot;</span>,c1.<span style="color: #006600;">s</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; test fun If2MyClassesWithTheSamePropertiesAreEqual<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; val c1 = MyClass<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #ff0000;">&quot;t&quot;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; val c2 = MyClass<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #ff0000;">&quot;t&quot;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; assertTrue<span style="color: #66cc66;">&#40;</span>c1.<span style="color: #006600;">equals</span><span style="color: #66cc66;">&#40;</span>c2<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; test fun If2MyClassesWithDifferentPropertiesAreNotEqual<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; val c1 = MyClass<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #ff0000;">&quot;t&quot;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; val c2 = MyClass<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span>,<span style="color: #ff0000;">&quot;t&quot;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; assertFalse<span style="color: #66cc66;">&#40;</span>c1.<span style="color: #006600;">equals</span><span style="color: #66cc66;">&#40;</span>c2<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; test fun IfToStringReturnsTheCorrectString<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; val c1 = MyClass<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>, <span style="color: #ff0000;">&quot;t&quot;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; assertEquals<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;MyClass(i=1, s=t)&quot;</span>,c1.<span style="color: #006600;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></li><li style="" class="li2"><span style="color: #66cc66;">&#125;</span></li></ol></div><div id="cb1937" style="display: none; color: red;"></div></div></div>

<p>You might think this is the same class as in my previous blogpost but it isn't. My previous class was called testMyClass and by convention Maven only finds Test*, *Test or TestCase* classes. I found that out the hard way. Lucky me.</p>

<p>Anyway, your project should look like this.</p>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlinandmaven5.png?mtime=1354535218"><img alt="" src="http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlinandmaven5.png?mtime=1354535218" width="387" height="348" /></a></div>

<p>And now when we open our Maven project view. we should see this.</p>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlinandmaven6.png?mtime=1354535357"><img alt="" src="http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlinandmaven6.png?mtime=1354535357" width="465" height="528" /></a></div>

<p>you can now doubleclick on test and see the magic happen.</p>

<p>This should be the result.</p>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlinandmaven7.png?mtime=1354535495"><img alt="" src="http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlinandmaven7.png?mtime=1354535495" width="742" height="313" /></a></div>

<p>5 tests run and none faild. Woohoo.</p>

<h2>Conclusion</h2>

<p>It took me a while to get it to work since I could not find Maven and IntelliJ for dummies and the Maven site is full of XML. But it works and I'm happy. Now on to Spek and getting the package into a repo, be afraid, be very afraid.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DesktopDev/SunTech/Java/kotlin-and-maven">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DesktopDev/SunTech/Java/kotlin-and-maven#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DesktopDev/?tempskin=_rss2&#38;disp=comments&#38;p=1927</wfw:commentRss>
		</item>
				<item>
			<title>Kotlin and testing</title>
			<link>http://blogs.lessthandot.com/index.php/DesktopDev/SunTech/Java/kotlin-and-testing</link>
			<pubDate>Sun, 02 Dec 2012 12:28:00 +0000</pubDate>			<dc:creator>Christiaan Baes (chrissie1)</dc:creator>
			<category domain="main">Java</category>			<guid isPermaLink="false">1924@http://blogs.lessthandot.com/</guid>
						<description>&lt;h2&gt;Introduction&lt;/h2&gt;

&lt;p&gt;When learning a language it is important to know how to write unittests for it. Most modern languages have testing built in. And Kotlin is no exception. Kotlin has the kotlin.test namespace that has all the asserts you need. &lt;/p&gt;

&lt;h2&gt;Configuration&lt;/h2&gt;

&lt;p&gt;You will find plenty of examples how to write tests with Kotlin but something was escaping me because my tests would not run.&lt;/p&gt;

&lt;p&gt;Let&#039;s take our class.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;java&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;java&quot; id=&quot;cb53511&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;package&lt;/span&gt; demo&lt;br /&gt;&amp;nbsp;&lt;br /&gt;data &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; MyClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;val i : Int, val s : &lt;a href=&quot;http://www.google.com/search?hl=en&amp;amp;q=allinurl%3AString+java.sun.com&amp;amp;btnI=I%27m%20Feeling%20Lucky&quot;&gt;&lt;span style=&quot;color: #aaaadd; font-weight: bold;&quot;&gt;String&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb64075&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;uhm yeah.&lt;/p&gt;

&lt;p&gt;Now lets try our first test.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;java&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;java&quot; id=&quot;cb12617&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;package&lt;/span&gt; demo.&lt;span style=&quot;color: #006600;&quot;&gt;test&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #a1a100;&quot;&gt;import demo.MyClass&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #a1a100;&quot;&gt;import kotlin.test.assertEquals&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; tests&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; test fun IfPropertyIIsSetCorrectly&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; val c1 = MyClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;t&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; assertEquals&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;,c1.&lt;span style=&quot;color: #006600;&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb47633&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;I was excpeting the above to run. It doesn&#039;t give a compilation error but the Intellij testrunner doesn&#039;t like it. So I was doing something wrong.&lt;/p&gt;

&lt;p&gt;The thing I missed was that it also needs JUnit. You can get maven to download and install it.&lt;/p&gt;

&lt;p&gt;And add this line to you import.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;java&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;java&quot; id=&quot;cb51653&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #a1a100;&quot;&gt;import org.junit.Test as test&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb23651&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now the intellij testrunner will like them and run them.&lt;/p&gt;

&lt;h2&gt;More tests.&lt;/h2&gt;

&lt;p&gt;And here are some more tests.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;text&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;text&quot; id=&quot;cb13825&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;package demo.test&lt;br /&gt;&amp;nbsp;&lt;br /&gt;import demo.MyClass&lt;br /&gt;import kotlin.test.assertEquals&lt;br /&gt;import org.junit.Test as test&lt;br /&gt;import kotlin.test.assertTrue&lt;br /&gt;import kotlin.test.assertFalse&lt;br /&gt;&amp;nbsp;&lt;br /&gt;public class tests&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; &amp;nbsp; test fun IfPropertyIIsSetCorrectly()&lt;br /&gt;&amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; val c1 = MyClass(1,&amp;quot;t&amp;quot;)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; assertEquals(1,c1.i)&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; test fun IfPropertySIsSetCorrectly()&lt;br /&gt;&amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; val c1 = MyClass(1,&amp;quot;t&amp;quot;)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; assertEquals(&amp;quot;t&amp;quot;,c1.s)&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; test fun If2MyClassesWithTheSamePropertiesAreEqual()&lt;br /&gt;&amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; val c1 = MyClass(1,&amp;quot;t&amp;quot;)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; val c2 = MyClass(1,&amp;quot;t&amp;quot;)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; assertTrue(c1.equals(c2))&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; test fun If2MyClassesWithDifferentPropertiesAreNotEqual()&lt;br /&gt;&amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; val c1 = MyClass(1,&amp;quot;t&amp;quot;)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; val c2 = MyClass(2,&amp;quot;t&amp;quot;)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; assertFalse(c1.equals(c2))&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; test fun IfToStringReturnsTheCorrectString()&lt;br /&gt;&amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; val c1 = MyClass(1, &amp;quot;t&amp;quot;)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; assertEquals(&amp;quot;MyClass(i=1, s=t)&amp;quot;,c1.toString())&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb28897&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;But you can just as well do this.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;java&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;java&quot; id=&quot;cb71016&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;package&lt;/span&gt; demo.&lt;span style=&quot;color: #006600;&quot;&gt;test&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #a1a100;&quot;&gt;import demo.MyClass&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #a1a100;&quot;&gt;import org.junit.Assert.assertEquals&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #a1a100;&quot;&gt;import org.junit.Test as test&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #a1a100;&quot;&gt;import org.junit.Assert.assertTrue&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #a1a100;&quot;&gt;import org.junit.Assert.assertFalse&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; tests&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; test fun IfPropertyIIsSetCorrectly&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; val c1 = MyClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;t&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; assertEquals&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;,c1.&lt;span style=&quot;color: #006600;&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; test fun IfPropertySIsSetCorrectly&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; val c1 = MyClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;t&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; assertEquals&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;t&amp;quot;&lt;/span&gt;,c1.&lt;span style=&quot;color: #006600;&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; test fun If2MyClassesWithTheSamePropertiesAreEqual&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; val c1 = MyClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;t&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; val c2 = MyClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;t&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; assertTrue&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;c1.&lt;span style=&quot;color: #006600;&quot;&gt;equals&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;c2&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; test fun If2MyClassesWithDifferentPropertiesAreNotEqual&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; val c1 = MyClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;t&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; val c2 = MyClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt;,&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;t&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; assertFalse&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;c1.&lt;span style=&quot;color: #006600;&quot;&gt;equals&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;c2&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; test fun IfToStringReturnsTheCorrectString&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; val c1 = MyClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;t&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; assertEquals&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;MyClass(i=1, s=t)&amp;quot;&lt;/span&gt;,c1.&lt;span style=&quot;color: #006600;&quot;&gt;toString&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb4725&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Notice the difference?&lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;Not sure if kotlin.test adds much. We can just as well use Junit directly, you need it anyway.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DesktopDev/SunTech/Java/kotlin-and-testing&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<h2>Introduction</h2>

<p>When learning a language it is important to know how to write unittests for it. Most modern languages have testing built in. And Kotlin is no exception. Kotlin has the kotlin.test namespace that has all the asserts you need. </p>

<h2>Configuration</h2>

<p>You will find plenty of examples how to write tests with Kotlin but something was escaping me because my tests would not run.</p>

<p>Let's take our class.</p>

<div class="codebox"><div class="codeheader"><span>java</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb88659'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb88659','cb55835'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="java" id="cb88659" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #000000; font-weight: bold;">package</span> demo</li><li style="" class="li2">&nbsp;</li><li style="" class="li1">data <span style="color: #000000; font-weight: bold;">class</span> MyClass<span style="color: #66cc66;">&#40;</span>val i : Int, val s : <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">String</span></a><span style="color: #66cc66;">&#41;</span></li></ol></div><div id="cb55835" style="display: none; color: red;"></div></div></div>

<p>uhm yeah.</p>

<p>Now lets try our first test.</p>

<div class="codebox"><div class="codeheader"><span>java</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb81686'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb81686','cb89340'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="java" id="cb81686" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #000000; font-weight: bold;">package</span> demo.<span style="color: #006600;">test</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #a1a100;">import demo.MyClass</span></li><li style="" class="li2"><span style="color: #a1a100;">import kotlin.test.assertEquals</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> tests</li><li style="" class="li1"><span style="color: #66cc66;">&#123;</span></li><li style="" class="li2">&nbsp; &nbsp; test fun IfPropertyIIsSetCorrectly<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; val c1 = MyClass<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #ff0000;">&quot;t&quot;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; assertEquals<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,c1.<span style="color: #006600;">i</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></li><li style="" class="li1"><span style="color: #66cc66;">&#125;</span></li></ol></div><div id="cb89340" style="display: none; color: red;"></div></div></div>

<p>I was excpeting the above to run. It doesn't give a compilation error but the Intellij testrunner doesn't like it. So I was doing something wrong.</p>

<p>The thing I missed was that it also needs JUnit. You can get maven to download and install it.</p>

<p>And add this line to you import.</p>

<div class="codebox"><div class="codeheader"><span>java</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb71141'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb71141','cb1998'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="java" id="cb71141" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #a1a100;">import org.junit.Test as test</span></li></ol></div><div id="cb1998" style="display: none; color: red;"></div></div></div>

<p>Now the intellij testrunner will like them and run them.</p>

<h2>More tests.</h2>

<p>And here are some more tests.</p>

<div class="codebox"><div class="codeheader"><span>text</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb50677'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb50677','cb64080'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="text" id="cb50677" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">package demo.test</li><li style="" class="li2">&nbsp;</li><li style="" class="li1">import demo.MyClass</li><li style="" class="li2">import kotlin.test.assertEquals</li><li style="" class="li1">import org.junit.Test as test</li><li style="" class="li2">import kotlin.test.assertTrue</li><li style="" class="li1">import kotlin.test.assertFalse</li><li style="" class="li2">&nbsp;</li><li style="" class="li1">public class tests</li><li style="" class="li2">{</li><li style="" class="li1">&nbsp; &nbsp; test fun IfPropertyIIsSetCorrectly()</li><li style="" class="li2">&nbsp; &nbsp; {</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; val c1 = MyClass(1,&quot;t&quot;)</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; assertEquals(1,c1.i)</li><li style="" class="li1">&nbsp; &nbsp; }</li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; test fun IfPropertySIsSetCorrectly()</li><li style="" class="li2">&nbsp; &nbsp; {</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; val c1 = MyClass(1,&quot;t&quot;)</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; assertEquals(&quot;t&quot;,c1.s)</li><li style="" class="li1">&nbsp; &nbsp; }</li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; test fun If2MyClassesWithTheSamePropertiesAreEqual()</li><li style="" class="li2">&nbsp; &nbsp; {</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; val c1 = MyClass(1,&quot;t&quot;)</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; val c2 = MyClass(1,&quot;t&quot;)</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; assertTrue(c1.equals(c2))</li><li style="" class="li2">&nbsp; &nbsp; }</li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; test fun If2MyClassesWithDifferentPropertiesAreNotEqual()</li><li style="" class="li1">&nbsp; &nbsp; {</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; val c1 = MyClass(1,&quot;t&quot;)</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; val c2 = MyClass(2,&quot;t&quot;)</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; assertFalse(c1.equals(c2))</li><li style="" class="li1">&nbsp; &nbsp; }</li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; test fun IfToStringReturnsTheCorrectString()</li><li style="" class="li2">&nbsp; &nbsp; {</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; val c1 = MyClass(1, &quot;t&quot;)</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; assertEquals(&quot;MyClass(i=1, s=t)&quot;,c1.toString())</li><li style="" class="li1">&nbsp; &nbsp; }</li><li style="" class="li2">}</li></ol></div><div id="cb64080" style="display: none; color: red;"></div></div></div>

<p>But you can just as well do this.</p>

<div class="codebox"><div class="codeheader"><span>java</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb74508'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb74508','cb93712'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="java" id="cb74508" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #000000; font-weight: bold;">package</span> demo.<span style="color: #006600;">test</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #a1a100;">import demo.MyClass</span></li><li style="" class="li2"><span style="color: #a1a100;">import org.junit.Assert.assertEquals</span></li><li style="" class="li1"><span style="color: #a1a100;">import org.junit.Test as test</span></li><li style="" class="li2"><span style="color: #a1a100;">import org.junit.Assert.assertTrue</span></li><li style="" class="li1"><span style="color: #a1a100;">import org.junit.Assert.assertFalse</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> tests</li><li style="" class="li2"><span style="color: #66cc66;">&#123;</span></li><li style="" class="li1">&nbsp; &nbsp; test fun IfPropertyIIsSetCorrectly<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; val c1 = MyClass<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #ff0000;">&quot;t&quot;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; assertEquals<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,c1.<span style="color: #006600;">i</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; test fun IfPropertySIsSetCorrectly<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; val c1 = MyClass<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #ff0000;">&quot;t&quot;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; assertEquals<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;t&quot;</span>,c1.<span style="color: #006600;">s</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; test fun If2MyClassesWithTheSamePropertiesAreEqual<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; val c1 = MyClass<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #ff0000;">&quot;t&quot;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; val c2 = MyClass<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #ff0000;">&quot;t&quot;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; assertTrue<span style="color: #66cc66;">&#40;</span>c1.<span style="color: #006600;">equals</span><span style="color: #66cc66;">&#40;</span>c2<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; test fun If2MyClassesWithDifferentPropertiesAreNotEqual<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; val c1 = MyClass<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #ff0000;">&quot;t&quot;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; val c2 = MyClass<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span>,<span style="color: #ff0000;">&quot;t&quot;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; assertFalse<span style="color: #66cc66;">&#40;</span>c1.<span style="color: #006600;">equals</span><span style="color: #66cc66;">&#40;</span>c2<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; test fun IfToStringReturnsTheCorrectString<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; val c1 = MyClass<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>, <span style="color: #ff0000;">&quot;t&quot;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; assertEquals<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;MyClass(i=1, s=t)&quot;</span>,c1.<span style="color: #006600;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></li><li style="" class="li2"><span style="color: #66cc66;">&#125;</span></li></ol></div><div id="cb93712" style="display: none; color: red;"></div></div></div>

<p>Notice the difference?</p>

<h2>Conclusion</h2>

<p>Not sure if kotlin.test adds much. We can just as well use Junit directly, you need it anyway.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DesktopDev/SunTech/Java/kotlin-and-testing">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DesktopDev/SunTech/Java/kotlin-and-testing#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DesktopDev/?tempskin=_rss2&#38;disp=comments&#38;p=1924</wfw:commentRss>
		</item>
				<item>
			<title>Your queue is not threadsafe and sometimes that can give unwanted sideeffects</title>
			<link>http://blogs.lessthandot.com/index.php/DesktopDev/MSTech/VBNET/your-queue-is-not-threadsafe</link>
			<pubDate>Wed, 28 Nov 2012 06:58:00 +0000</pubDate>			<dc:creator>Christiaan Baes (chrissie1)</dc:creator>
			<category domain="alt">Microsoft Technologies</category>
<category domain="main">VB.NET</category>			<guid isPermaLink="false">1911@http://blogs.lessthandot.com/</guid>
						<description>&lt;h2&gt;Introduction&lt;/h2&gt;

&lt;p&gt;For one of my projects I needed to show the 30 last messages to the user. I was not interested in keeping these messages. So I decided to use a queue. The messages come from different sources and different threads. &lt;/p&gt;

&lt;p&gt;And the different threads bit is important. &lt;/p&gt;

&lt;h2&gt;The queue&lt;/h2&gt;

&lt;p&gt;Here is what can happen if you use the not threadsafe queue.&lt;/p&gt;

&lt;p&gt;Let&#039;s take this little example.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;vbnet&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;vbnet&quot; id=&quot;cb40601&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;Imports System.&lt;span style=&quot;color: #000000;&quot;&gt;Threading&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;Module&lt;/span&gt; Module1&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Private&lt;/span&gt; _queue &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; Queue&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;Of &lt;span style=&quot;color: #0600FF;&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Private&lt;/span&gt; _count &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Integer&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt; Main&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.&lt;span style=&quot;color: #000000;&quot;&gt;WriteLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;Not concurrent threads&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; _count = &lt;span style=&quot;color: #FF0000;&quot;&gt;0&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Dim&lt;/span&gt; t &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;New&lt;/span&gt; Thread&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;New&lt;/span&gt; ParameterizedThreadStart&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; Addmessages&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; AddMessage&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Dim&lt;/span&gt; t2 &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;New&lt;/span&gt; Thread&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;New&lt;/span&gt; ParameterizedThreadStart&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; Addmessages&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; AddMessage&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Dim&lt;/span&gt; t3 &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;New&lt;/span&gt; Thread&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;New&lt;/span&gt; ParameterizedThreadStart&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; Addmessages&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; AddMessage&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Dim&lt;/span&gt; t4 &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;New&lt;/span&gt; Thread&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;New&lt;/span&gt; ParameterizedThreadStart&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; Addmessages&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; AddMessage&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; t.&lt;span style=&quot;color: #000000;&quot;&gt;Start&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; t2.&lt;span style=&quot;color: #000000;&quot;&gt;Start&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; t3.&lt;span style=&quot;color: #000000;&quot;&gt;Start&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; t4.&lt;span style=&quot;color: #000000;&quot;&gt;Start&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Do While _count &amp;lt; &lt;span style=&quot;color: #FF0000;&quot;&gt;4&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Loop&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; _count = &lt;span style=&quot;color: #FF0000;&quot;&gt;1&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;For&lt;/span&gt; Each q In _queue.&lt;span style=&quot;color: #000000;&quot;&gt;Reverse&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;ToList&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.&lt;span style=&quot;color: #000000;&quot;&gt;WriteLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;_count &amp;amp; &lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;. &amp;quot;&lt;/span&gt; &amp;amp; q&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; _count += &lt;span style=&quot;color: #FF0000;&quot;&gt;1&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Next&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.&lt;span style=&quot;color: #000000;&quot;&gt;ReadLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Public&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt; Addmessages&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;ByVal&lt;/span&gt; action &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; Action&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;Of &lt;span style=&quot;color: #0600FF;&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;For&lt;/span&gt; x = &lt;span style=&quot;color: #FF0000;&quot;&gt;1&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;To&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;1000000&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; action.&lt;span style=&quot;color: #000000;&quot;&gt;Invoke&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;test&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Next&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; _count += &lt;span style=&quot;color: #FF0000;&quot;&gt;1&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Public&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt; AddMessage&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;message &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; If _Queue &lt;span style=&quot;color: #0600FF;&quot;&gt;Is&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Nothing&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Then&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; _queue = &lt;span style=&quot;color: #0600FF;&quot;&gt;New&lt;/span&gt; Queue&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;Of &lt;span style=&quot;color: #0600FF;&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #FF0000;&quot;&gt;1000000&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; If&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; If Not &lt;span style=&quot;color: #0600FF;&quot;&gt;String&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;IsNullOrEmpty&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;message&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Then&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; _Queue.&lt;span style=&quot;color: #000000;&quot;&gt;Enqueue&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;message&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; If&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Dim&lt;/span&gt; result &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;String&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; If _queue.&lt;span style=&quot;color: #000000;&quot;&gt;Count&lt;/span&gt; &amp;gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;10&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Then&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; _queue.&lt;span style=&quot;color: #000000;&quot;&gt;Dequeue&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; If&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Module&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb64392&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;That is 4 threads that add 1000000 messages to the queue at an alarming rate. And I only want to keep the last 10 messages in my queue.&lt;/p&gt;

&lt;p&gt;The result. &lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;128683. test&lt;br /&gt;
128684. test&lt;br /&gt;
128685. test&lt;br /&gt;
128686. test&lt;br /&gt;
128687. test&lt;br /&gt;
128688. test&lt;br /&gt;
128689. test&lt;br /&gt;
128690.&lt;br /&gt;
128691. test&lt;br /&gt;
128692. test&lt;br /&gt;
128693. test&lt;br /&gt;
128694. test&lt;br /&gt;
128695. test&lt;br /&gt;
128696. test&lt;br /&gt;
128697. test&lt;br /&gt;
128698. test&lt;br /&gt;
128699. test&lt;br /&gt;
128700. test&lt;br /&gt;
128701. test&lt;br /&gt;
128702. test&lt;br /&gt;
128703. test&lt;br /&gt;
128704. test&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Those are only the last ones. There are 128704 elements in our queue and some are empty. Not sure how I get the empty ones but I guess it must be somewhere between an enqueue and a dequeue. &lt;/p&gt;

&lt;p&gt;Anyway the results are not what we desire. &lt;/p&gt;

&lt;p&gt;And of course now I could start adding blocks here and there to make sure the enqueue and dequeue are atomic operations and what not but Since .Net 4.0 there are Concurent collections and they are threadsafe by design. Lucky us.&lt;/p&gt;

&lt;h2&gt;The concurrent queue&lt;/h2&gt;

&lt;p&gt;We can simply change our code to this.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;vbnet&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;vbnet&quot; id=&quot;cb91724&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;Imports System.&lt;span style=&quot;color: #000000;&quot;&gt;Collections&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;Concurrent&lt;/span&gt;&lt;br /&gt;Imports System.&lt;span style=&quot;color: #000000;&quot;&gt;Threading&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;Module&lt;/span&gt; Module1&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Private&lt;/span&gt; _concurrentQueue &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; ConcurrentQueue&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;Of &lt;span style=&quot;color: #0600FF;&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Private&lt;/span&gt; _count &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Integer&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt; Main&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.&lt;span style=&quot;color: #000000;&quot;&gt;WriteLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;concurrent threads&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; _count = &lt;span style=&quot;color: #FF0000;&quot;&gt;0&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Dim&lt;/span&gt; t5 &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;New&lt;/span&gt; Thread&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;New&lt;/span&gt; ParameterizedThreadStart&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; Addmessages&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; AddMessageConcurrently&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Dim&lt;/span&gt; t6 &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;New&lt;/span&gt; Thread&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;New&lt;/span&gt; ParameterizedThreadStart&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; Addmessages&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; AddMessageConcurrently&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Dim&lt;/span&gt; t7 &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;New&lt;/span&gt; Thread&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;New&lt;/span&gt; ParameterizedThreadStart&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; Addmessages&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; AddMessageConcurrently&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Dim&lt;/span&gt; t8 &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;New&lt;/span&gt; Thread&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;New&lt;/span&gt; ParameterizedThreadStart&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; Addmessages&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; AddMessageConcurrently&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;x&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; t5.&lt;span style=&quot;color: #000000;&quot;&gt;Start&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; t6.&lt;span style=&quot;color: #000000;&quot;&gt;Start&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; t7.&lt;span style=&quot;color: #000000;&quot;&gt;Start&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; t8.&lt;span style=&quot;color: #000000;&quot;&gt;Start&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Do While _count &amp;lt; &lt;span style=&quot;color: #FF0000;&quot;&gt;4&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Loop&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; _count = &lt;span style=&quot;color: #FF0000;&quot;&gt;1&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;For&lt;/span&gt; Each q In _concurrentQueue.&lt;span style=&quot;color: #000000;&quot;&gt;Reverse&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;ToList&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.&lt;span style=&quot;color: #000000;&quot;&gt;WriteLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;_count &amp;amp; &lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;. &amp;quot;&lt;/span&gt; &amp;amp; q&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; _count += &lt;span style=&quot;color: #FF0000;&quot;&gt;1&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Next&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.&lt;span style=&quot;color: #000000;&quot;&gt;ReadLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Public&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt; Addmessages&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;ByVal&lt;/span&gt; action &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; Action&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;Of &lt;span style=&quot;color: #0600FF;&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;For&lt;/span&gt; x = &lt;span style=&quot;color: #FF0000;&quot;&gt;1&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;To&lt;/span&gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;1000000&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; action.&lt;span style=&quot;color: #000000;&quot;&gt;Invoke&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;test&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Next&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; _count += &lt;span style=&quot;color: #FF0000;&quot;&gt;1&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Public&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt; AddMessageConcurrently&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;message &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; If _concurrentQueue &lt;span style=&quot;color: #0600FF;&quot;&gt;Is&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Nothing&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Then&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; _concurrentQueue = &lt;span style=&quot;color: #0600FF;&quot;&gt;New&lt;/span&gt; ConcurrentQueue&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;Of &lt;span style=&quot;color: #0600FF;&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; If&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; If Not &lt;span style=&quot;color: #0600FF;&quot;&gt;String&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;IsNullOrEmpty&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;message&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Then&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; _concurrentQueue.&lt;span style=&quot;color: #000000;&quot;&gt;Enqueue&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;message&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; If&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Dim&lt;/span&gt; result &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;String&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; If _concurrentQueue.&lt;span style=&quot;color: #000000;&quot;&gt;Count&lt;/span&gt; &amp;gt; &lt;span style=&quot;color: #FF0000;&quot;&gt;10&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Then&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; _concurrentQueue.&lt;span style=&quot;color: #000000;&quot;&gt;TryDequeue&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;result&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; If&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Module&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb64250&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And now the result is.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;concurrent threads&lt;br /&gt;
1. test&lt;br /&gt;
2. test&lt;br /&gt;
3. test&lt;br /&gt;
4. test&lt;br /&gt;
5. test&lt;br /&gt;
6. test&lt;br /&gt;
7. test&lt;br /&gt;
8. test&lt;br /&gt;
9. test&lt;br /&gt;
10. test&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;And that is exactly what I expected.&lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;There is a namespace in .Net since 4.0 that contains threadsafe collections. And it is there for you to use. I would however not overuse it since I expect the blocking to have an effect on performance.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DesktopDev/MSTech/VBNET/your-queue-is-not-threadsafe&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<h2>Introduction</h2>

<p>For one of my projects I needed to show the 30 last messages to the user. I was not interested in keeping these messages. So I decided to use a queue. The messages come from different sources and different threads. </p>

<p>And the different threads bit is important. </p>

<h2>The queue</h2>

<p>Here is what can happen if you use the not threadsafe queue.</p>

<p>Let's take this little example.</p>

<div class="codebox"><div class="codeheader"><span>vbnet</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb93835'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb93835','cb30086'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="vbnet" id="cb93835" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">Imports System.<span style="color: #000000;">Threading</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #0600FF;">Module</span> Module1</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #0600FF;">Private</span> _queue <span style="color: #0600FF;">As</span> Queue<span style="color: #000000;">&#40;</span>Of <span style="color: #0600FF;">String</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #0600FF;">Private</span> _count <span style="color: #0600FF;">As</span> <span style="color: #0600FF;">Integer</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #0600FF;">Sub</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #000000;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">&quot;Not concurrent threads&quot;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; _count = <span style="color: #FF0000;">0</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> t <span style="color: #0600FF;">As</span> <span style="color: #0600FF;">New</span> Thread<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">New</span> ParameterizedThreadStart<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">Sub</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> Addmessages<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">Sub</span><span style="color: #000000;">&#40;</span>x<span style="color: #000000;">&#41;</span> AddMessage<span style="color: #000000;">&#40;</span>x<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> t2 <span style="color: #0600FF;">As</span> <span style="color: #0600FF;">New</span> Thread<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">New</span> ParameterizedThreadStart<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">Sub</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> Addmessages<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">Sub</span><span style="color: #000000;">&#40;</span>x<span style="color: #000000;">&#41;</span> AddMessage<span style="color: #000000;">&#40;</span>x<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> t3 <span style="color: #0600FF;">As</span> <span style="color: #0600FF;">New</span> Thread<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">New</span> ParameterizedThreadStart<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">Sub</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> Addmessages<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">Sub</span><span style="color: #000000;">&#40;</span>x<span style="color: #000000;">&#41;</span> AddMessage<span style="color: #000000;">&#40;</span>x<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> t4 <span style="color: #0600FF;">As</span> <span style="color: #0600FF;">New</span> Thread<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">New</span> ParameterizedThreadStart<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">Sub</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> Addmessages<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">Sub</span><span style="color: #000000;">&#40;</span>x<span style="color: #000000;">&#41;</span> AddMessage<span style="color: #000000;">&#40;</span>x<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; t.<span style="color: #000000;">Start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; t2.<span style="color: #000000;">Start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; t3.<span style="color: #000000;">Start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; t4.<span style="color: #000000;">Start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; Do While _count &lt; <span style="color: #FF0000;">4</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; Loop</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; _count = <span style="color: #FF0000;">1</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">For</span> Each q In _queue.<span style="color: #000000;">Reverse</span>.<span style="color: #000000;">ToList</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #000000;">WriteLine</span><span style="color: #000000;">&#40;</span>_count &amp; <span style="color: #0600FF;">&quot;. &quot;</span> &amp; q<span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _count += <span style="color: #FF0000;">1</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Next</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #000000;">ReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #0600FF;">Public</span> <span style="color: #0600FF;">Sub</span> Addmessages<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">ByVal</span> action <span style="color: #0600FF;">As</span> Action<span style="color: #000000;">&#40;</span>Of <span style="color: #0600FF;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">For</span> x = <span style="color: #FF0000;">1</span> <span style="color: #0600FF;">To</span> <span style="color: #FF0000;">1000000</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; action.<span style="color: #000000;">Invoke</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">&quot;test&quot;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Next</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; _count += <span style="color: #FF0000;">1</span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #0600FF;">Public</span> <span style="color: #0600FF;">Sub</span> AddMessage<span style="color: #000000;">&#40;</span>message <span style="color: #0600FF;">As</span> <span style="color: #0600FF;">String</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; If _Queue <span style="color: #0600FF;">Is</span> <span style="color: #0600FF;">Nothing</span> <span style="color: #0600FF;">Then</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _queue = <span style="color: #0600FF;">New</span> Queue<span style="color: #000000;">&#40;</span>Of <span style="color: #0600FF;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1000000</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">End</span> If</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; If Not <span style="color: #0600FF;">String</span>.<span style="color: #000000;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>message<span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">Then</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _Queue.<span style="color: #000000;">Enqueue</span><span style="color: #000000;">&#40;</span>message<span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">End</span> If</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> result <span style="color: #0600FF;">As</span> <span style="color: #0600FF;">String</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; If _queue.<span style="color: #000000;">Count</span> &gt; <span style="color: #FF0000;">10</span> <span style="color: #0600FF;">Then</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _queue.<span style="color: #000000;">Dequeue</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">End</span> If</li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Module</span></li></ol></div><div id="cb30086" style="display: none; color: red;"></div></div></div>

<p>That is 4 threads that add 1000000 messages to the queue at an alarming rate. And I only want to keep the last 10 messages in my queue.</p>

<p>The result. </p>

<blockquote><p>128683. test<br />
128684. test<br />
128685. test<br />
128686. test<br />
128687. test<br />
128688. test<br />
128689. test<br />
128690.<br />
128691. test<br />
128692. test<br />
128693. test<br />
128694. test<br />
128695. test<br />
128696. test<br />
128697. test<br />
128698. test<br />
128699. test<br />
128700. test<br />
128701. test<br />
128702. test<br />
128703. test<br />
128704. test</p></blockquote>

<p>Those are only the last ones. There are 128704 elements in our queue and some are empty. Not sure how I get the empty ones but I guess it must be somewhere between an enqueue and a dequeue. </p>

<p>Anyway the results are not what we desire. </p>

<p>And of course now I could start adding blocks here and there to make sure the enqueue and dequeue are atomic operations and what not but Since .Net 4.0 there are Concurent collections and they are threadsafe by design. Lucky us.</p>

<h2>The concurrent queue</h2>

<p>We can simply change our code to this.</p>

<div class="codebox"><div class="codeheader"><span>vbnet</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb21343'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb21343','cb63155'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="vbnet" id="cb21343" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">Imports System.<span style="color: #000000;">Collections</span>.<span style="color: #000000;">Concurrent</span></li><li style="" class="li2">Imports System.<span style="color: #000000;">Threading</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #0600FF;">Module</span> Module1</li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #0600FF;">Private</span> _concurrentQueue <span style="color: #0600FF;">As</span> ConcurrentQueue<span style="color: #000000;">&#40;</span>Of <span style="color: #0600FF;">String</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #0600FF;">Private</span> _count <span style="color: #0600FF;">As</span> <span style="color: #0600FF;">Integer</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #0600FF;">Sub</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #000000;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">&quot;concurrent threads&quot;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; _count = <span style="color: #FF0000;">0</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> t5 <span style="color: #0600FF;">As</span> <span style="color: #0600FF;">New</span> Thread<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">New</span> ParameterizedThreadStart<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">Sub</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> Addmessages<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">Sub</span><span style="color: #000000;">&#40;</span>x<span style="color: #000000;">&#41;</span> AddMessageConcurrently<span style="color: #000000;">&#40;</span>x<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> t6 <span style="color: #0600FF;">As</span> <span style="color: #0600FF;">New</span> Thread<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">New</span> ParameterizedThreadStart<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">Sub</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> Addmessages<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">Sub</span><span style="color: #000000;">&#40;</span>x<span style="color: #000000;">&#41;</span> AddMessageConcurrently<span style="color: #000000;">&#40;</span>x<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> t7 <span style="color: #0600FF;">As</span> <span style="color: #0600FF;">New</span> Thread<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">New</span> ParameterizedThreadStart<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">Sub</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> Addmessages<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">Sub</span><span style="color: #000000;">&#40;</span>x<span style="color: #000000;">&#41;</span> AddMessageConcurrently<span style="color: #000000;">&#40;</span>x<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> t8 <span style="color: #0600FF;">As</span> <span style="color: #0600FF;">New</span> Thread<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">New</span> ParameterizedThreadStart<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">Sub</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> Addmessages<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">Sub</span><span style="color: #000000;">&#40;</span>x<span style="color: #000000;">&#41;</span> AddMessageConcurrently<span style="color: #000000;">&#40;</span>x<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; t5.<span style="color: #000000;">Start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; t6.<span style="color: #000000;">Start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; t7.<span style="color: #000000;">Start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; t8.<span style="color: #000000;">Start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; Do While _count &lt; <span style="color: #FF0000;">4</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; Loop</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; _count = <span style="color: #FF0000;">1</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">For</span> Each q In _concurrentQueue.<span style="color: #000000;">Reverse</span>.<span style="color: #000000;">ToList</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #000000;">WriteLine</span><span style="color: #000000;">&#40;</span>_count &amp; <span style="color: #0600FF;">&quot;. &quot;</span> &amp; q<span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _count += <span style="color: #FF0000;">1</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Next</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #000000;">ReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #0600FF;">Public</span> <span style="color: #0600FF;">Sub</span> Addmessages<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">ByVal</span> action <span style="color: #0600FF;">As</span> Action<span style="color: #000000;">&#40;</span>Of <span style="color: #0600FF;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">For</span> x = <span style="color: #FF0000;">1</span> <span style="color: #0600FF;">To</span> <span style="color: #FF0000;">1000000</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; action.<span style="color: #000000;">Invoke</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">&quot;test&quot;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Next</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; _count += <span style="color: #FF0000;">1</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #0600FF;">Public</span> <span style="color: #0600FF;">Sub</span> AddMessageConcurrently<span style="color: #000000;">&#40;</span>message <span style="color: #0600FF;">As</span> <span style="color: #0600FF;">String</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; If _concurrentQueue <span style="color: #0600FF;">Is</span> <span style="color: #0600FF;">Nothing</span> <span style="color: #0600FF;">Then</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _concurrentQueue = <span style="color: #0600FF;">New</span> ConcurrentQueue<span style="color: #000000;">&#40;</span>Of <span style="color: #0600FF;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">End</span> If</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; If Not <span style="color: #0600FF;">String</span>.<span style="color: #000000;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>message<span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">Then</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _concurrentQueue.<span style="color: #000000;">Enqueue</span><span style="color: #000000;">&#40;</span>message<span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">End</span> If</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> result <span style="color: #0600FF;">As</span> <span style="color: #0600FF;">String</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; If _concurrentQueue.<span style="color: #000000;">Count</span> &gt; <span style="color: #FF0000;">10</span> <span style="color: #0600FF;">Then</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _concurrentQueue.<span style="color: #000000;">TryDequeue</span><span style="color: #000000;">&#40;</span>result<span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">End</span> If</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Module</span></li></ol></div><div id="cb63155" style="display: none; color: red;"></div></div></div>

<p>And now the result is.</p>

<blockquote><p>concurrent threads<br />
1. test<br />
2. test<br />
3. test<br />
4. test<br />
5. test<br />
6. test<br />
7. test<br />
8. test<br />
9. test<br />
10. test</p></blockquote>

<p>And that is exactly what I expected.</p>

<h2>Conclusion</h2>

<p>There is a namespace in .Net since 4.0 that contains threadsafe collections. And it is there for you to use. I would however not overuse it since I expect the blocking to have an effect on performance.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DesktopDev/MSTech/VBNET/your-queue-is-not-threadsafe">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DesktopDev/MSTech/VBNET/your-queue-is-not-threadsafe#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DesktopDev/?tempskin=_rss2&#38;disp=comments&#38;p=1911</wfw:commentRss>
		</item>
				<item>
			<title>Kotlin: val and var</title>
			<link>http://blogs.lessthandot.com/index.php/DesktopDev/SunTech/Java/kotlin-val-and-var</link>
			<pubDate>Sun, 25 Nov 2012 06:46:00 +0000</pubDate>			<dc:creator>Christiaan Baes (chrissie1)</dc:creator>
			<category domain="main">Java</category>			<guid isPermaLink="false">1905@http://blogs.lessthandot.com/</guid>
						<description>&lt;h2&gt;Introduction&lt;/h2&gt;

&lt;p&gt;I am now using kotlin plugin 0.4.221 while I was using 0.4.214 just yesterday.&lt;/p&gt;

&lt;p&gt;In the last couple of weeks I started dabbling in kotlin a bit and wrote &lt;a href=&quot;http://blogs.lessthandot.com/index.php/DesktopDev/SunTech/Java/kotlin-the-data-class-and&quot;&gt;a first blogpost about the data class,&lt;/a&gt; because the data class was a new concept that I have not yet encountered in one of the many programminglanguages I have used over the years. But that probably means I have just been using the wrong ones all these years. Another new concept for me was the val keyword. &lt;/p&gt;

&lt;p&gt;The val keyword tells the compiler that our object is immutable.&lt;/p&gt;

&lt;h2&gt;To val or not to val&lt;/h2&gt;

&lt;p&gt;So let&#039;s see what that means.&lt;/p&gt;

&lt;p&gt;Let&#039;s make a data class with a val property and a var property.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;java&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;java&quot; id=&quot;cb606&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;data &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; MyClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;var i : Int, val s : &lt;a href=&quot;http://www.google.com/search?hl=en&amp;amp;q=allinurl%3AString+java.sun.com&amp;amp;btnI=I%27m%20Feeling%20Lucky&quot;&gt;&lt;span style=&quot;color: #aaaadd; font-weight: bold;&quot;&gt;String&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb62991&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And now let&#039;s try and use our class, like this.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;java&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;java&quot; id=&quot;cb40918&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;fun main&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;args : Array&amp;lt;String&amp;gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; val c1 = MyClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;t&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; c1.&lt;span style=&quot;color: #006600;&quot;&gt;i&lt;/span&gt; = &lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; c1.&lt;span style=&quot;color: #006600;&quot;&gt;s&lt;/span&gt; = &lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;s&amp;quot;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb25844&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;you will get an error on the &lt;code class=&quot;codespan&quot;&gt;c1.s = &quot;s&quot;&lt;/code&gt; line because s is immutable and has been set in the constructor.&lt;/p&gt;

&lt;div class=&quot;image_block&quot;&gt;&lt;a href=&quot;http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlin1.png?mtime=1353831918&quot;&gt;&lt;img alt=&quot;&quot; src=&quot;http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlin1.png?mtime=1353831918&quot; width=&quot;279&quot; height=&quot;124&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;You might have noticed that we instantiated our class with the val keyword as well. this means you can no longer assign another instance to it..&lt;/p&gt;

&lt;p&gt;So when I try this.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;java&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;java&quot; id=&quot;cb43352&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;c1 = MyClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;s&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb66866&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt; &lt;/p&gt;

&lt;p&gt;I will get the same error as before.&lt;/p&gt;

&lt;p&gt;So if you want to change an immutable class then you will have to create another instance and start passing that along.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;java&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;java&quot; id=&quot;cb23836&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;data &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; MyClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;val i : Int, val s : &lt;a href=&quot;http://www.google.com/search?hl=en&amp;amp;q=allinurl%3AString+java.sun.com&amp;amp;btnI=I%27m%20Feeling%20Lucky&quot;&gt;&lt;span style=&quot;color: #aaaadd; font-weight: bold;&quot;&gt;String&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;fun main&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;args : Array&amp;lt;String&amp;gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; val c1 = MyClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;t&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; println&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;c1.&lt;span style=&quot;color: #006600;&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; println&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;c1.&lt;span style=&quot;color: #006600;&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; val c2 = MyClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;c1.&lt;span style=&quot;color: #006600;&quot;&gt;i&lt;/span&gt;,&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;s&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; println&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;c2.&lt;span style=&quot;color: #006600;&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; println&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;c2.&lt;span style=&quot;color: #006600;&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb7051&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;Immutability is desirable a lot of the time, it protects you from unwanted side effects. &lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Immutable_object&quot;&gt;According to wikipedia.&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;Immutable objects are often useful because they are inherently thread-safe.[1] Other benefits are that they are simpler to understand and reason about and offer higher security than mutable objects.&lt;/p&gt;&lt;/blockquote&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DesktopDev/SunTech/Java/kotlin-val-and-var&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<h2>Introduction</h2>

<p>I am now using kotlin plugin 0.4.221 while I was using 0.4.214 just yesterday.</p>

<p>In the last couple of weeks I started dabbling in kotlin a bit and wrote <a href="http://blogs.lessthandot.com/index.php/DesktopDev/SunTech/Java/kotlin-the-data-class-and">a first blogpost about the data class,</a> because the data class was a new concept that I have not yet encountered in one of the many programminglanguages I have used over the years. But that probably means I have just been using the wrong ones all these years. Another new concept for me was the val keyword. </p>

<p>The val keyword tells the compiler that our object is immutable.</p>

<h2>To val or not to val</h2>

<p>So let's see what that means.</p>

<p>Let's make a data class with a val property and a var property.</p>

<div class="codebox"><div class="codeheader"><span>java</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb97869'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb97869','cb15280'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="java" id="cb97869" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">data <span style="color: #000000; font-weight: bold;">class</span> MyClass<span style="color: #66cc66;">&#40;</span>var i : Int, val s : <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">String</span></a><span style="color: #66cc66;">&#41;</span></li></ol></div><div id="cb15280" style="display: none; color: red;"></div></div></div>

<p>And now let's try and use our class, like this.</p>

<div class="codebox"><div class="codeheader"><span>java</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb62571'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb62571','cb66538'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="java" id="cb62571" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">fun main<span style="color: #66cc66;">&#40;</span>args : Array&lt;String&gt;<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></li><li style="" class="li2">&nbsp; &nbsp; val c1 = MyClass<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #ff0000;">&quot;t&quot;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; c1.<span style="color: #006600;">i</span> = <span style="color: #cc66cc;">2</span></li><li style="" class="li2">&nbsp; &nbsp; c1.<span style="color: #006600;">s</span> = <span style="color: #ff0000;">&quot;s&quot;</span></li><li style="" class="li1"><span style="color: #66cc66;">&#125;</span></li></ol></div><div id="cb66538" style="display: none; color: red;"></div></div></div>

<p>you will get an error on the <code class="codespan">c1.s = "s"</code> line because s is immutable and has been set in the constructor.</p>

<div class="image_block"><a href="http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlin1.png?mtime=1353831918"><img alt="" src="http://blogs.lessthandot.com/media/users/chrissie1/kotlin/kotlin1.png?mtime=1353831918" width="279" height="124" /></a></div>

<p>You might have noticed that we instantiated our class with the val keyword as well. this means you can no longer assign another instance to it..</p>

<p>So when I try this.</p>

<div class="codebox"><div class="codeheader"><span>java</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb43610'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb43610','cb15942'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="java" id="cb43610" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">c1 = MyClass<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #ff0000;">&quot;s&quot;</span><span style="color: #66cc66;">&#41;</span></li></ol></div><div id="cb15942" style="display: none; color: red;"></div></div></div><p> </p>

<p>I will get the same error as before.</p>

<p>So if you want to change an immutable class then you will have to create another instance and start passing that along.</p>

<div class="codebox"><div class="codeheader"><span>java</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb63808'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb63808','cb71217'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="java" id="cb63808" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">data <span style="color: #000000; font-weight: bold;">class</span> MyClass<span style="color: #66cc66;">&#40;</span>val i : Int, val s : <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">String</span></a><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">fun main<span style="color: #66cc66;">&#40;</span>args : Array&lt;String&gt;<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></li><li style="" class="li2">&nbsp; &nbsp; val c1 = MyClass<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #ff0000;">&quot;t&quot;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; println<span style="color: #66cc66;">&#40;</span>c1.<span style="color: #006600;">i</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; println<span style="color: #66cc66;">&#40;</span>c1.<span style="color: #006600;">s</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; val c2 = MyClass<span style="color: #66cc66;">&#40;</span>c1.<span style="color: #006600;">i</span>,<span style="color: #ff0000;">&quot;s&quot;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; println<span style="color: #66cc66;">&#40;</span>c2.<span style="color: #006600;">i</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; println<span style="color: #66cc66;">&#40;</span>c2.<span style="color: #006600;">s</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2"><span style="color: #66cc66;">&#125;</span></li></ol></div><div id="cb71217" style="display: none; color: red;"></div></div></div>

<h2>Conclusion</h2>

<p>Immutability is desirable a lot of the time, it protects you from unwanted side effects. </p>

<p><a href="http://en.wikipedia.org/wiki/Immutable_object">According to wikipedia.</a></p>

<blockquote><p>Immutable objects are often useful because they are inherently thread-safe.[1] Other benefits are that they are simpler to understand and reason about and offer higher security than mutable objects.</p></blockquote><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DesktopDev/SunTech/Java/kotlin-val-and-var">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DesktopDev/SunTech/Java/kotlin-val-and-var#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DesktopDev/?tempskin=_rss2&#38;disp=comments&#38;p=1905</wfw:commentRss>
		</item>
				<item>
			<title>Kotlin the data class and the class</title>
			<link>http://blogs.lessthandot.com/index.php/DesktopDev/SunTech/Java/kotlin-the-data-class-and</link>
			<pubDate>Sat, 24 Nov 2012 06:41:00 +0000</pubDate>			<dc:creator>Christiaan Baes (chrissie1)</dc:creator>
			<category domain="main">Java</category>			<guid isPermaLink="false">1904@http://blogs.lessthandot.com/</guid>
						<description>&lt;h2&gt;Introduction&lt;/h2&gt;

&lt;p&gt;Over the last few weeks I have been playing around with &lt;a href=&quot;http://confluence.jetbrains.net/display/Kotlin/Getting+Started&quot;&gt;Kotlin&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;First let me tell you that it can be a bit frustrating because Kotlin is far from a finished product. It works on an EAP version of IntelliJ with nightly builds of the plugin. So you are bound to have version that don&#039;t work. I had 2 of those over the last week. But it now works with &lt;a href=&quot;http://eap.jetbrains.com/idea&quot;&gt;IntelliJ 123.4&lt;/a&gt; and kotlin plugin &lt;a href=&quot;http://teamcity.jetbrains.com/viewType.html?tab=buildTypeStatusDiv&amp;amp;buildTypeId=bt345&amp;amp;guest=1&quot;&gt;0.4.214&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;And that things still change can be proven by the fact that the samples use tuples while tuples have been removed and replaced by data classes. So you can expect to find errors in the documentation and in the samples on github. &lt;/p&gt;

&lt;p&gt;But we are here to learn. And I found the concept of the data class very intriguing.&lt;/p&gt;

&lt;h2&gt;The class&lt;/h2&gt;

&lt;p&gt;in kotlin you can define a class like this.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;java&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;java&quot; id=&quot;cb83972&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; MyClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;val i : Int, val s : &lt;a href=&quot;http://www.google.com/search?hl=en&amp;amp;q=allinurl%3AString+java.sun.com&amp;amp;btnI=I%27m%20Feeling%20Lucky&quot;&gt;&lt;span style=&quot;color: #aaaadd; font-weight: bold;&quot;&gt;String&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb40013&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt; &lt;/p&gt;

&lt;p&gt;That&#039;s a class with two properties named i and s.&lt;/p&gt;

&lt;p&gt;And we can read out all the usual methods like this.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;java&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;java&quot; id=&quot;cb77203&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;fun main&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;args : Array&amp;lt;String&amp;gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; val c1 = MyClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;t&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; val c2 = MyClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;t&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; val c3 = MyClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt;,&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;t&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; println&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;c1.&lt;span style=&quot;color: #006600;&quot;&gt;toString&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; println&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;c1.&lt;span style=&quot;color: #006600;&quot;&gt;equals&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;c2&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; println&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;c1.&lt;span style=&quot;color: #006600;&quot;&gt;equals&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;c3&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; println&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;c1.&lt;span style=&quot;color: #006600;&quot;&gt;equals&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;c1&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; println&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;c1.&lt;span style=&quot;color: #006600;&quot;&gt;hashCode&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; println&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;c2.&lt;span style=&quot;color: #006600;&quot;&gt;hashCode&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; println&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;c3.&lt;span style=&quot;color: #006600;&quot;&gt;hashCode&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; println&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;c1.&lt;span style=&quot;color: #006600;&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; println&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;c1.&lt;span style=&quot;color: #006600;&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb72434&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;with this as the result.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;demo.MyClass@337d0f&lt;br /&gt;
false&lt;br /&gt;
false&lt;br /&gt;
true&lt;br /&gt;
3374351&lt;br /&gt;
21356612&lt;br /&gt;
8831815&lt;br /&gt;
1&lt;br /&gt;
t&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;That&#039;s how I would expect any class to behave even in .Net and Java. Nothing special.&lt;/p&gt;

&lt;h2&gt;The data class&lt;/h2&gt;

&lt;p&gt;Now lets add the keyword data in front of it.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;java&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;java&quot; id=&quot;cb65083&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;data &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; MyClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;val i : Int, val s : &lt;a href=&quot;http://www.google.com/search?hl=en&amp;amp;q=allinurl%3AString+java.sun.com&amp;amp;btnI=I%27m%20Feeling%20Lucky&quot;&gt;&lt;span style=&quot;color: #aaaadd; font-weight: bold;&quot;&gt;String&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb68428&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;and run our code again.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;MyClass(i=1, s=t)&lt;br /&gt;
true&lt;br /&gt;
false&lt;br /&gt;
true&lt;br /&gt;
147&lt;br /&gt;
147&lt;br /&gt;
178&lt;br /&gt;
1&lt;br /&gt;
t&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;the result is completely different. c1 and c2 are the same the tostring is differnt and the hashcodes are different.&lt;/p&gt;

&lt;p&gt;The data class behaves as a DTO.&lt;/p&gt;

&lt;p&gt;But the data class is also a tupple.&lt;/p&gt;

&lt;p&gt;Which we can demonstrate by adding these two lines to our main.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;java&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;java&quot; id=&quot;cb12451&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;println&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;c1.&lt;span style=&quot;color: #006600;&quot;&gt;component1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; println&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;c1.&lt;span style=&quot;color: #006600;&quot;&gt;component2&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb26577&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Which will now give us the following output.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;MyClass(i=1, s=t)&lt;br /&gt;
true&lt;br /&gt;
false&lt;br /&gt;
true&lt;br /&gt;
147&lt;br /&gt;
147&lt;br /&gt;
178&lt;br /&gt;
1&lt;br /&gt;
t&lt;br /&gt;
1&lt;br /&gt;
t&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Just like a tupple.&lt;/p&gt;

&lt;p&gt;So tostring, equals and hashcode are autoimplemented for a data class and based on the properties you provide. &lt;/p&gt;

&lt;p&gt;But you can also override that behavior if you want.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;java&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;java&quot; id=&quot;cb54313&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;data &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; MyClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;val i : Int, val s : &lt;a href=&quot;http://www.google.com/search?hl=en&amp;amp;q=allinurl%3AString+java.sun.com&amp;amp;btnI=I%27m%20Feeling%20Lucky&quot;&gt;&lt;span style=&quot;color: #aaaadd; font-weight: bold;&quot;&gt;String&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; fun equals&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;val obj : &lt;a href=&quot;http://www.google.com/search?hl=en&amp;amp;q=allinurl%3AAny+java.sun.com&amp;amp;btnI=I%27m%20Feeling%20Lucky&quot;&gt;&lt;span style=&quot;color: #aaaadd; font-weight: bold;&quot;&gt;Any&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; : &lt;a href=&quot;http://www.google.com/search?hl=en&amp;amp;q=allinurl%3ABoolean+java.sun.com&amp;amp;btnI=I%27m%20Feeling%20Lucky&quot;&gt;&lt;span style=&quot;color: #aaaadd; font-weight: bold;&quot;&gt;Boolean&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;obj as MyClass&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;s&lt;/span&gt;.&lt;span style=&quot;color: #006600;&quot;&gt;equals&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;s&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; fun hashCode&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; : Int&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;return&lt;/span&gt; s.&lt;span style=&quot;color: #006600;&quot;&gt;hashCode&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; fun toString&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; : &lt;a href=&quot;http://www.google.com/search?hl=en&amp;amp;q=allinurl%3AString+java.sun.com&amp;amp;btnI=I%27m%20Feeling%20Lucky&quot;&gt;&lt;span style=&quot;color: #aaaadd; font-weight: bold;&quot;&gt;String&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;return&lt;/span&gt; s.&lt;span style=&quot;color: #006600;&quot;&gt;toString&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb50574&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;with this as the result.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;t&lt;br /&gt;
true&lt;br /&gt;
true&lt;br /&gt;
true&lt;br /&gt;
116&lt;br /&gt;
116&lt;br /&gt;
116&lt;br /&gt;
1&lt;br /&gt;
t&lt;br /&gt;
1&lt;br /&gt;
t&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Cool.&lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;I very much like the data class and it would come in handy in many other languages.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DesktopDev/SunTech/Java/kotlin-the-data-class-and&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<h2>Introduction</h2>

<p>Over the last few weeks I have been playing around with <a href="http://confluence.jetbrains.net/display/Kotlin/Getting+Started">Kotlin</a>. </p>

<p>First let me tell you that it can be a bit frustrating because Kotlin is far from a finished product. It works on an EAP version of IntelliJ with nightly builds of the plugin. So you are bound to have version that don't work. I had 2 of those over the last week. But it now works with <a href="http://eap.jetbrains.com/idea">IntelliJ 123.4</a> and kotlin plugin <a href="http://teamcity.jetbrains.com/viewType.html?tab=buildTypeStatusDiv&amp;buildTypeId=bt345&amp;guest=1">0.4.214</a>.</p>

<p>And that things still change can be proven by the fact that the samples use tuples while tuples have been removed and replaced by data classes. So you can expect to find errors in the documentation and in the samples on github. </p>

<p>But we are here to learn. And I found the concept of the data class very intriguing.</p>

<h2>The class</h2>

<p>in kotlin you can define a class like this.</p>

<div class="codebox"><div class="codeheader"><span>java</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb37077'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb37077','cb16456'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="java" id="cb37077" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1"><span style="color: #000000; font-weight: bold;">class</span> MyClass<span style="color: #66cc66;">&#40;</span>val i : Int, val s : <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">String</span></a><span style="color: #66cc66;">&#41;</span></li></ol></div><div id="cb16456" style="display: none; color: red;"></div></div></div><p> </p>

<p>That's a class with two properties named i and s.</p>

<p>And we can read out all the usual methods like this.</p>

<div class="codebox"><div class="codeheader"><span>java</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb32064'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb32064','cb15827'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="java" id="cb32064" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">fun main<span style="color: #66cc66;">&#40;</span>args : Array&lt;String&gt;<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></li><li style="" class="li2">&nbsp; &nbsp; val c1 = MyClass<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #ff0000;">&quot;t&quot;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; val c2 = MyClass<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span>,<span style="color: #ff0000;">&quot;t&quot;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; val c3 = MyClass<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">2</span>,<span style="color: #ff0000;">&quot;t&quot;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; println<span style="color: #66cc66;">&#40;</span>c1.<span style="color: #006600;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; println<span style="color: #66cc66;">&#40;</span>c1.<span style="color: #006600;">equals</span><span style="color: #66cc66;">&#40;</span>c2<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; println<span style="color: #66cc66;">&#40;</span>c1.<span style="color: #006600;">equals</span><span style="color: #66cc66;">&#40;</span>c3<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; println<span style="color: #66cc66;">&#40;</span>c1.<span style="color: #006600;">equals</span><span style="color: #66cc66;">&#40;</span>c1<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; println<span style="color: #66cc66;">&#40;</span>c1.<span style="color: #006600;">hashCode</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; println<span style="color: #66cc66;">&#40;</span>c2.<span style="color: #006600;">hashCode</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; println<span style="color: #66cc66;">&#40;</span>c3.<span style="color: #006600;">hashCode</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; println<span style="color: #66cc66;">&#40;</span>c1.<span style="color: #006600;">i</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; println<span style="color: #66cc66;">&#40;</span>c1.<span style="color: #006600;">s</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2"><span style="color: #66cc66;">&#125;</span></li></ol></div><div id="cb15827" style="display: none; color: red;"></div></div></div>

<p>with this as the result.</p>

<blockquote><p>demo.MyClass@337d0f<br />
false<br />
false<br />
true<br />
3374351<br />
21356612<br />
8831815<br />
1<br />
t</p></blockquote>

<p>That's how I would expect any class to behave even in .Net and Java. Nothing special.</p>

<h2>The data class</h2>

<p>Now lets add the keyword data in front of it.</p>

<div class="codebox"><div class="codeheader"><span>java</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb23592'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb23592','cb59196'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="java" id="cb23592" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">data <span style="color: #000000; font-weight: bold;">class</span> MyClass<span style="color: #66cc66;">&#40;</span>val i : Int, val s : <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">String</span></a><span style="color: #66cc66;">&#41;</span></li></ol></div><div id="cb59196" style="display: none; color: red;"></div></div></div>

<p>and run our code again.</p>

<blockquote><p>MyClass(i=1, s=t)<br />
true<br />
false<br />
true<br />
147<br />
147<br />
178<br />
1<br />
t</p></blockquote>

<p>the result is completely different. c1 and c2 are the same the tostring is differnt and the hashcodes are different.</p>

<p>The data class behaves as a DTO.</p>

<p>But the data class is also a tupple.</p>

<p>Which we can demonstrate by adding these two lines to our main.</p>

<div class="codebox"><div class="codeheader"><span>java</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb10880'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb10880','cb28961'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="java" id="cb10880" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">println<span style="color: #66cc66;">&#40;</span>c1.<span style="color: #006600;">component1</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; println<span style="color: #66cc66;">&#40;</span>c1.<span style="color: #006600;">component2</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></li></ol></div><div id="cb28961" style="display: none; color: red;"></div></div></div>

<p>Which will now give us the following output.</p>

<blockquote><p>MyClass(i=1, s=t)<br />
true<br />
false<br />
true<br />
147<br />
147<br />
178<br />
1<br />
t<br />
1<br />
t</p></blockquote>

<p>Just like a tupple.</p>

<p>So tostring, equals and hashcode are autoimplemented for a data class and based on the properties you provide. </p>

<p>But you can also override that behavior if you want.</p>

<div class="codebox"><div class="codeheader"><span>java</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb27424'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb27424','cb23663'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="java" id="cb27424" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">data <span style="color: #000000; font-weight: bold;">class</span> MyClass<span style="color: #66cc66;">&#40;</span>val i : Int, val s : <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">String</span></a><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2"><span style="color: #66cc66;">&#123;</span></li><li style="" class="li1">&nbsp; &nbsp; fun equals<span style="color: #66cc66;">&#40;</span>val obj : <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AAny+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">Any</span></a><span style="color: #66cc66;">&#41;</span> : <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ABoolean+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">Boolean</span></a> <span style="color: #66cc66;">&#123;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #66cc66;">&#40;</span>obj as MyClass<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">s</span>.<span style="color: #006600;">equals</span><span style="color: #66cc66;">&#40;</span>s<span style="color: #66cc66;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; fun hashCode<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : Int</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> s.<span style="color: #006600;">hashCode</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; fun toString<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> : <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">String</span></a> <span style="color: #66cc66;">&#123;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> s.<span style="color: #006600;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></li><li style="" class="li1"><span style="color: #66cc66;">&#125;</span></li></ol></div><div id="cb23663" style="display: none; color: red;"></div></div></div>

<p>with this as the result.</p>

<blockquote><p>t<br />
true<br />
true<br />
true<br />
116<br />
116<br />
116<br />
1<br />
t<br />
1<br />
t</p>
</blockquote>

<p>Cool.</p>

<h2>Conclusion</h2>

<p>I very much like the data class and it would come in handy in many other languages.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DesktopDev/SunTech/Java/kotlin-the-data-class-and">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DesktopDev/SunTech/Java/kotlin-the-data-class-and#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DesktopDev/?tempskin=_rss2&#38;disp=comments&#38;p=1904</wfw:commentRss>
		</item>
				<item>
			<title>Json.Net 's JObject to dynamic in VB.Net</title>
			<link>http://blogs.lessthandot.com/index.php/DesktopDev/MSTech/json-net-s-jobject-to</link>
			<pubDate>Sun, 11 Nov 2012 12:44:00 +0000</pubDate>			<dc:creator>Christiaan Baes (chrissie1)</dc:creator>
			<category domain="main">Microsoft Technologies</category>
<category domain="alt">VB.NET</category>			<guid isPermaLink="false">1892@http://blogs.lessthandot.com/</guid>
						<description>&lt;p&gt;In my &lt;a href=&quot;http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/signalr-and-vb-net-hubs&quot;&gt;previous post&lt;/a&gt; I showed you how to get an object from a call to a SignalR method.&lt;/p&gt;

&lt;p&gt;That call on the client side returns a &lt;a href=&quot;http://json.codeplex.com/&quot;&gt;Json.Net&lt;/a&gt; JObject. This is dynamic object.&lt;/p&gt;

&lt;p&gt;However, the implementation of this object is not very VB.Net friendly. &lt;/p&gt;

&lt;p&gt;If you try this.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;vbnet&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;vbnet&quot; id=&quot;cb84230&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;Imports System.&lt;span style=&quot;color: #000000;&quot;&gt;Runtime&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;CompilerServices&lt;/span&gt;&lt;br /&gt;Imports Newtonsoft.&lt;span style=&quot;color: #000000;&quot;&gt;Json&lt;/span&gt;&lt;br /&gt;Imports Newtonsoft.&lt;span style=&quot;color: #000000;&quot;&gt;Json&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;Linq&lt;/span&gt;&lt;br /&gt;Imports Microsoft.&lt;span style=&quot;color: #000000;&quot;&gt;AspNet&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;SignalR&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;Client&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;Hubs&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;Module&lt;/span&gt; Module1&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt; Main&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Dim&lt;/span&gt; connection = &lt;span style=&quot;color: #0600FF;&quot;&gt;New&lt;/span&gt; HubConnection&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;http://localhost:50865&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Dim&lt;/span&gt; plants = connection.&lt;span style=&quot;color: #000000;&quot;&gt;CreateHubProxy&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;Plants&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; plants.&lt;span style=&quot;color: #0600FF;&quot;&gt;On&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;Of &lt;span style=&quot;color: #0600FF;&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;addMessage&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;data&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; Console.&lt;span style=&quot;color: #000000;&quot;&gt;WriteLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;data.&lt;span style=&quot;color: #000000;&quot;&gt;ToString&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; connection.&lt;span style=&quot;color: #000000;&quot;&gt;Start&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;Wait&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Dim&lt;/span&gt; line &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;String&lt;/span&gt; = &lt;span style=&quot;color: #0600FF;&quot;&gt;Nothing&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.&lt;span style=&quot;color: #000000;&quot;&gt;WriteLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;type the id + enter to send, type exit + enter to exit.&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; While line &amp;lt;&amp;gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;exit&amp;quot;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; line = Console.&lt;span style=&quot;color: #000000;&quot;&gt;ReadLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; plants.&lt;span style=&quot;color: #000000;&quot;&gt;Invoke&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;Of Object&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;GetPlant&amp;quot;&lt;/span&gt;, line&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;ContinueWith&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;data&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; If data.&lt;span style=&quot;color: #000000;&quot;&gt;Result&lt;/span&gt; IsNot &lt;span style=&quot;color: #0600FF;&quot;&gt;Nothing&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Then&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.&lt;span style=&quot;color: #000000;&quot;&gt;WriteLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;data.&lt;span style=&quot;color: #000000;&quot;&gt;Result&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;ToString&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Dim&lt;/span&gt; result = data.&lt;span style=&quot;color: #000000;&quot;&gt;Result&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.&lt;span style=&quot;color: #000000;&quot;&gt;WriteLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;result.&lt;span style=&quot;color: #000000;&quot;&gt;Id&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.&lt;span style=&quot;color: #000000;&quot;&gt;WriteLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;result.&lt;span style=&quot;color: #000000;&quot;&gt;Genus&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.&lt;span style=&quot;color: #000000;&quot;&gt;WriteLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;result.&lt;span style=&quot;color: #000000;&quot;&gt;Species&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;For&lt;/span&gt; Each commonName In result.&lt;span style=&quot;color: #000000;&quot;&gt;CommonNames&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.&lt;span style=&quot;color: #000000;&quot;&gt;WriteLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;commonName&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Next&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Else&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.&lt;span style=&quot;color: #000000;&quot;&gt;WriteLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;No plant with that id.&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; If&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; While&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Module&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb41370&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;


&lt;p&gt;You will get an exception on result.Id&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;System.MissingMemberException was unhandled by user code&lt;br /&gt;
  HResult=-2146233070&lt;br /&gt;
  Message=Public member &#039;Id&#039; on type &#039;JObject&#039; not found.&lt;br /&gt;
  Source=Microsoft.VisualBasic&lt;br /&gt;
  StackTrace:&lt;br /&gt;
       at Microsoft.VisualBasic.CompilerServices.Symbols.Container.GetMembers(String&amp;amp; MemberName, Boolean ReportErrors)&lt;br /&gt;
       at Microsoft.VisualBasic.CompilerServices.NewLateBinding.ObjectLateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)&lt;br /&gt;
       at Microsoft.VisualBasic.CompilerServices.NewLateBinding.FallbackGet(Object Instance, String MemberName, Object[] Arguments, String[] ArgumentNames)&lt;br /&gt;
       at CallSite.Target(Closure , CallSite , Object )&lt;br /&gt;
       at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)&lt;br /&gt;
       at Invoker(CallSiteBinder , Object , Object[] )&lt;br /&gt;
       at Microsoft.VisualBasic.CompilerServices.IDOUtils.CreateRefCallSiteAndInvoke(CallSiteBinder Action, Object Instance, Object[] Arguments)&lt;br /&gt;
       at Microsoft.VisualBasic.CompilerServices.IDOBinder.IDOGet(IDynamicMetaObjectProvider Instance, String MemberName, Object[] Arguments, String[] ArgumentNames, Boolean[] CopyBack)&lt;br /&gt;
       at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)&lt;br /&gt;
       at SignalRConsole.Module1._Lambda$__2(Task`1 data) in E:\Users\christiaan\Documents\Visual Studio 2012\Projects\SignalRTesting\SignalRConsole\Module1.vb:line 25&lt;br /&gt;
       at System.Threading.Tasks.ContinuationTaskFromResultTask`1.InnerInvoke()&lt;br /&gt;
       at System.Threading.Tasks.Task.Execute()&lt;br /&gt;
  InnerException: &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The problem is the LateGet. But you can found out all about why this is a problem for VB.Net in the &lt;a href=&quot;http://www.broadcastbabble.com/why-vb-net-needs-a-dynamic-keyword/&quot;&gt;following post&lt;/a&gt; by Matthew Doig.&lt;/p&gt;

&lt;p&gt;And none of the Json.net converters can solve this for us. &lt;/p&gt;

&lt;p&gt;But we can use another library that does work with VB.Net.&lt;/p&gt;

&lt;p&gt;And it&#039;s called &lt;a href=&quot;http://www.jsonfx.net/&quot;&gt;JSonFX&lt;/a&gt;. Just add it to your project via Nuget and then we can change our code to this.&lt;/p&gt;

&lt;div class=&quot;codebox&quot;&gt;&lt;div class=&quot;codeheader&quot;&gt;Code: &lt;span&gt;vbnet&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;codeholder&quot;&gt;&lt;div class=&quot;vbnet&quot; id=&quot;cb27421&quot; style=&quot;display: block; color: rgb(0, 0, 0);&quot;&gt;Imports System.&lt;span style=&quot;color: #000000;&quot;&gt;Runtime&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;CompilerServices&lt;/span&gt;&lt;br /&gt;Imports Newtonsoft.&lt;span style=&quot;color: #000000;&quot;&gt;Json&lt;/span&gt;&lt;br /&gt;Imports Newtonsoft.&lt;span style=&quot;color: #000000;&quot;&gt;Json&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;Linq&lt;/span&gt;&lt;br /&gt;Imports Microsoft.&lt;span style=&quot;color: #000000;&quot;&gt;AspNet&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;SignalR&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;Client&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;Hubs&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;Module&lt;/span&gt; Module1&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt; Main&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Dim&lt;/span&gt; connection = &lt;span style=&quot;color: #0600FF;&quot;&gt;New&lt;/span&gt; HubConnection&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;http://localhost:50865&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Dim&lt;/span&gt; plants = connection.&lt;span style=&quot;color: #000000;&quot;&gt;CreateHubProxy&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;Plants&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; plants.&lt;span style=&quot;color: #0600FF;&quot;&gt;On&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;Of &lt;span style=&quot;color: #0600FF;&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;addMessage&amp;quot;&lt;/span&gt;, &lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;data&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt; Console.&lt;span style=&quot;color: #000000;&quot;&gt;WriteLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;data.&lt;span style=&quot;color: #000000;&quot;&gt;ToString&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; connection.&lt;span style=&quot;color: #000000;&quot;&gt;Start&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;Wait&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Dim&lt;/span&gt; line &lt;span style=&quot;color: #0600FF;&quot;&gt;As&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;String&lt;/span&gt; = &lt;span style=&quot;color: #0600FF;&quot;&gt;Nothing&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.&lt;span style=&quot;color: #000000;&quot;&gt;WriteLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;type the id + enter to send, type exit + enter to exit.&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; While line &amp;lt;&amp;gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;exit&amp;quot;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; line = Console.&lt;span style=&quot;color: #000000;&quot;&gt;ReadLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; plants.&lt;span style=&quot;color: #000000;&quot;&gt;Invoke&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;Of Object&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;GetPlant&amp;quot;&lt;/span&gt;, line&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;ContinueWith&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;data&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; If data.&lt;span style=&quot;color: #000000;&quot;&gt;Result&lt;/span&gt; IsNot &lt;span style=&quot;color: #0600FF;&quot;&gt;Nothing&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Then&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.&lt;span style=&quot;color: #000000;&quot;&gt;WriteLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;data.&lt;span style=&quot;color: #000000;&quot;&gt;Result&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;ToString&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Dim&lt;/span&gt; reader = &lt;span style=&quot;color: #0600FF;&quot;&gt;New&lt;/span&gt; JsonFx.&lt;span style=&quot;color: #000000;&quot;&gt;Json&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;JsonReader&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Dim&lt;/span&gt; result = reader.&lt;span style=&quot;color: #000000;&quot;&gt;Read&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;data.&lt;span style=&quot;color: #000000;&quot;&gt;Result&lt;/span&gt;.&lt;span style=&quot;color: #000000;&quot;&gt;ToString&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.&lt;span style=&quot;color: #000000;&quot;&gt;WriteLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;result.&lt;span style=&quot;color: #000000;&quot;&gt;Id&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.&lt;span style=&quot;color: #000000;&quot;&gt;WriteLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;result.&lt;span style=&quot;color: #000000;&quot;&gt;Genus&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.&lt;span style=&quot;color: #000000;&quot;&gt;WriteLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;result.&lt;span style=&quot;color: #000000;&quot;&gt;Species&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;For&lt;/span&gt; Each commonName In result.&lt;span style=&quot;color: #000000;&quot;&gt;CommonNames&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.&lt;span style=&quot;color: #000000;&quot;&gt;WriteLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;commonName&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Next&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;Else&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Console.&lt;span style=&quot;color: #000000;&quot;&gt;WriteLine&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;&amp;quot;No plant with that id.&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; If&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; While&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Sub&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;span style=&quot;color: #0600FF;&quot;&gt;End&lt;/span&gt; &lt;span style=&quot;color: #0600FF;&quot;&gt;Module&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div id=&quot;cb26555&quot; style=&quot;display: none; color: red;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now our result will be.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;type the id + enter to send, type exit + enter to exit.&lt;br /&gt;
1&lt;br /&gt;
{&lt;br /&gt;
  &quot;Id&quot;: 1,&lt;br /&gt;
  &quot;Genus&quot;: &quot;Fagus&quot;,&lt;br /&gt;
  &quot;Species&quot;: &quot;Sylvatica&quot;,&lt;br /&gt;
  &quot;CommonNames&quot;: [&lt;br /&gt;
    &quot;Common Beech&quot;&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
Someone requested id: 1&lt;br /&gt;
1&lt;br /&gt;
Fagus&lt;br /&gt;
Sylvatica&lt;br /&gt;
Common Beech&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Which is ultra cool.&lt;/p&gt;&lt;div class=&quot;item_footer&quot;&gt;&lt;p&gt;&lt;small&gt;&lt;a href=&quot;http://blogs.lessthandot.com/index.php/DesktopDev/MSTech/json-net-s-jobject-to&quot;&gt;Original post&lt;/a&gt; blogged on &lt;a href=&quot;http://lessthandot.com/&quot;&gt;LessThanDot&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;&lt;/div&gt;</description>
			<content:encoded><![CDATA[<p>In my <a href="http://blogs.lessthandot.com/index.php/WebDev/ServerProgramming/signalr-and-vb-net-hubs">previous post</a> I showed you how to get an object from a call to a SignalR method.</p>

<p>That call on the client side returns a <a href="http://json.codeplex.com/">Json.Net</a> JObject. This is dynamic object.</p>

<p>However, the implementation of this object is not very VB.Net friendly. </p>

<p>If you try this.</p>

<div class="codebox"><div class="codeheader"><span>vbnet</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb12128'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb12128','cb24422'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="vbnet" id="cb12128" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">Imports System.<span style="color: #000000;">Runtime</span>.<span style="color: #000000;">CompilerServices</span></li><li style="" class="li2">Imports Newtonsoft.<span style="color: #000000;">Json</span></li><li style="" class="li1">Imports Newtonsoft.<span style="color: #000000;">Json</span>.<span style="color: #000000;">Linq</span></li><li style="" class="li2">Imports Microsoft.<span style="color: #000000;">AspNet</span>.<span style="color: #000000;">SignalR</span>.<span style="color: #000000;">Client</span>.<span style="color: #000000;">Hubs</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #0600FF;">Module</span> Module1</li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #0600FF;">Sub</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> connection = <span style="color: #0600FF;">New</span> HubConnection<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">&quot;http://localhost:50865&quot;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> plants = connection.<span style="color: #000000;">CreateHubProxy</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">&quot;Plants&quot;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; plants.<span style="color: #0600FF;">On</span><span style="color: #000000;">&#40;</span>Of <span style="color: #0600FF;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">&quot;addMessage&quot;</span>, <span style="color: #0600FF;">Sub</span><span style="color: #000000;">&#40;</span>data<span style="color: #000000;">&#41;</span> Console.<span style="color: #000000;">WriteLine</span><span style="color: #000000;">&#40;</span>data.<span style="color: #000000;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; connection.<span style="color: #000000;">Start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">Wait</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> line <span style="color: #0600FF;">As</span> <span style="color: #0600FF;">String</span> = <span style="color: #0600FF;">Nothing</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #000000;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">&quot;type the id + enter to send, type exit + enter to exit.&quot;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; While line &lt;&gt; <span style="color: #0600FF;">&quot;exit&quot;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; line = Console.<span style="color: #000000;">ReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; plants.<span style="color: #000000;">Invoke</span><span style="color: #000000;">&#40;</span>Of Object<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">&quot;GetPlant&quot;</span>, line<span style="color: #000000;">&#41;</span>.<span style="color: #000000;">ContinueWith</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">Sub</span><span style="color: #000000;">&#40;</span>data<span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If data.<span style="color: #000000;">Result</span> IsNot <span style="color: #0600FF;">Nothing</span> <span style="color: #0600FF;">Then</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #000000;">WriteLine</span><span style="color: #000000;">&#40;</span>data.<span style="color: #000000;">Result</span>.<span style="color: #000000;">ToString</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> result = data.<span style="color: #000000;">Result</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #000000;">WriteLine</span><span style="color: #000000;">&#40;</span>result.<span style="color: #000000;">Id</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #000000;">WriteLine</span><span style="color: #000000;">&#40;</span>result.<span style="color: #000000;">Genus</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #000000;">WriteLine</span><span style="color: #000000;">&#40;</span>result.<span style="color: #000000;">Species</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">For</span> Each commonName In result.<span style="color: #000000;">CommonNames</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #000000;">WriteLine</span><span style="color: #000000;">&#40;</span>commonName<span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Next</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Else</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #000000;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">&quot;No plant with that id.&quot;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">End</span> If</li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">End</span> While</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Module</span></li></ol></div><div id="cb24422" style="display: none; color: red;"></div></div></div>


<p>You will get an exception on result.Id</p>

<blockquote><p>System.MissingMemberException was unhandled by user code<br />
  HResult=-2146233070<br />
  Message=Public member 'Id' on type 'JObject' not found.<br />
  Source=Microsoft.VisualBasic<br />
  StackTrace:<br />
       at Microsoft.VisualBasic.CompilerServices.Symbols.Container.GetMembers(String&amp; MemberName, Boolean ReportErrors)<br />
       at Microsoft.VisualBasic.CompilerServices.NewLateBinding.ObjectLateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)<br />
       at Microsoft.VisualBasic.CompilerServices.NewLateBinding.FallbackGet(Object Instance, String MemberName, Object[] Arguments, String[] ArgumentNames)<br />
       at CallSite.Target(Closure , CallSite , Object )<br />
       at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)<br />
       at Invoker(CallSiteBinder , Object , Object[] )<br />
       at Microsoft.VisualBasic.CompilerServices.IDOUtils.CreateRefCallSiteAndInvoke(CallSiteBinder Action, Object Instance, Object[] Arguments)<br />
       at Microsoft.VisualBasic.CompilerServices.IDOBinder.IDOGet(IDynamicMetaObjectProvider Instance, String MemberName, Object[] Arguments, String[] ArgumentNames, Boolean[] CopyBack)<br />
       at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)<br />
       at SignalRConsole.Module1._Lambda$__2(Task`1 data) in E:\Users\christiaan\Documents\Visual Studio 2012\Projects\SignalRTesting\SignalRConsole\Module1.vb:line 25<br />
       at System.Threading.Tasks.ContinuationTaskFromResultTask`1.InnerInvoke()<br />
       at System.Threading.Tasks.Task.Execute()<br />
  InnerException: </p>
</blockquote>

<p>The problem is the LateGet. But you can found out all about why this is a problem for VB.Net in the <a href="http://www.broadcastbabble.com/why-vb-net-needs-a-dynamic-keyword/">following post</a> by Matthew Doig.</p>

<p>And none of the Json.net converters can solve this for us. </p>

<p>But we can use another library that does work with VB.Net.</p>

<p>And it's called <a href="http://www.jsonfx.net/">JSonFX</a>. Just add it to your project via Nuget and then we can change our code to this.</p>

<div class="codebox"><div class="codeheader"><span>vbnet</span><div class="codebox_javascript_links"><a href="http://blogs.lessthandot.com" onclick="linenumberOnOff('cb70865'); return false;">Line number Off</a> | <a href="http://blogs.lessthandot.com#" onclick="expandCode('cb70865','cb17269'); return false;">Hide</a> | <a href="http://blogs.lessthandot.com#" onclick="selectCode(this); return false;">Select all</a></div></div><!-- we need this dummy div to fix a firefox bug when selecting code lines --><div class="codeholder"><div class="vbnet" id="cb70865" style="display: block; color: rgb(0, 0, 0);"><ol><li style="" class="li1">Imports System.<span style="color: #000000;">Runtime</span>.<span style="color: #000000;">CompilerServices</span></li><li style="" class="li2">Imports Newtonsoft.<span style="color: #000000;">Json</span></li><li style="" class="li1">Imports Newtonsoft.<span style="color: #000000;">Json</span>.<span style="color: #000000;">Linq</span></li><li style="" class="li2">Imports Microsoft.<span style="color: #000000;">AspNet</span>.<span style="color: #000000;">SignalR</span>.<span style="color: #000000;">Client</span>.<span style="color: #000000;">Hubs</span></li><li style="" class="li1">&nbsp;</li><li style="" class="li2"><span style="color: #0600FF;">Module</span> Module1</li><li style="" class="li1">&nbsp;</li><li style="" class="li2">&nbsp; &nbsp; <span style="color: #0600FF;">Sub</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> connection = <span style="color: #0600FF;">New</span> HubConnection<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">&quot;http://localhost:50865&quot;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> plants = connection.<span style="color: #000000;">CreateHubProxy</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">&quot;Plants&quot;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; plants.<span style="color: #0600FF;">On</span><span style="color: #000000;">&#40;</span>Of <span style="color: #0600FF;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">&quot;addMessage&quot;</span>, <span style="color: #0600FF;">Sub</span><span style="color: #000000;">&#40;</span>data<span style="color: #000000;">&#41;</span> Console.<span style="color: #000000;">WriteLine</span><span style="color: #000000;">&#40;</span>data.<span style="color: #000000;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; connection.<span style="color: #000000;">Start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">Wait</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> line <span style="color: #0600FF;">As</span> <span style="color: #0600FF;">String</span> = <span style="color: #0600FF;">Nothing</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #000000;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">&quot;type the id + enter to send, type exit + enter to exit.&quot;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; While line &lt;&gt; <span style="color: #0600FF;">&quot;exit&quot;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; line = Console.<span style="color: #000000;">ReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; plants.<span style="color: #000000;">Invoke</span><span style="color: #000000;">&#40;</span>Of Object<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">&quot;GetPlant&quot;</span>, line<span style="color: #000000;">&#41;</span>.<span style="color: #000000;">ContinueWith</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">Sub</span><span style="color: #000000;">&#40;</span>data<span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If data.<span style="color: #000000;">Result</span> IsNot <span style="color: #0600FF;">Nothing</span> <span style="color: #0600FF;">Then</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #000000;">WriteLine</span><span style="color: #000000;">&#40;</span>data.<span style="color: #000000;">Result</span>.<span style="color: #000000;">ToString</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> reader = <span style="color: #0600FF;">New</span> JsonFx.<span style="color: #000000;">Json</span>.<span style="color: #000000;">JsonReader</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> result = reader.<span style="color: #000000;">Read</span><span style="color: #000000;">&#40;</span>data.<span style="color: #000000;">Result</span>.<span style="color: #000000;">ToString</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #000000;">WriteLine</span><span style="color: #000000;">&#40;</span>result.<span style="color: #000000;">Id</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #000000;">WriteLine</span><span style="color: #000000;">&#40;</span>result.<span style="color: #000000;">Genus</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #000000;">WriteLine</span><span style="color: #000000;">&#40;</span>result.<span style="color: #000000;">Species</span><span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">For</span> Each commonName In result.<span style="color: #000000;">CommonNames</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #000000;">WriteLine</span><span style="color: #000000;">&#40;</span>commonName<span style="color: #000000;">&#41;</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Next</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Else</span></li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #000000;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">&quot;No plant with that id.&quot;</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">End</span> If</li><li style="" class="li1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span><span style="color: #000000;">&#41;</span></li><li style="" class="li2">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">End</span> While</li><li style="" class="li1">&nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></li><li style="" class="li2">&nbsp;</li><li style="" class="li1"><span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Module</span></li></ol></div><div id="cb17269" style="display: none; color: red;"></div></div></div>

<p>Now our result will be.</p>

<blockquote><p>type the id + enter to send, type exit + enter to exit.<br />
1<br />
{<br />
  "Id": 1,<br />
  "Genus": "Fagus",<br />
  "Species": "Sylvatica",<br />
  "CommonNames": [<br />
    "Common Beech"<br />
  ]<br />
}<br />
Someone requested id: 1<br />
1<br />
Fagus<br />
Sylvatica<br />
Common Beech</p></blockquote>

<p>Which is ultra cool.</p><div class="item_footer"><p><small><a href="http://blogs.lessthandot.com/index.php/DesktopDev/MSTech/json-net-s-jobject-to">Original post</a> blogged on <a href="http://lessthandot.com/">LessThanDot</a>.</small></p></div>]]></content:encoded>
								<comments>http://blogs.lessthandot.com/index.php/DesktopDev/MSTech/json-net-s-jobject-to#comments</comments>
			<wfw:commentRss>http://blogs.lessthandot.com/index.php/DesktopDev/?tempskin=_rss2&#38;disp=comments&#38;p=1892</wfw:commentRss>
		</item>
			</channel>
</rss>
