<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>.net &#8211; martinklinke.com</title>
	<atom:link href="https://www.martinklinke.com/tag/net/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.martinklinke.com</link>
	<description>IT&#039;s my business</description>
	<lastBuildDate>Wed, 01 Jun 2016 21:15:21 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>
	<item>
		<title>How to generate C# code in 2016</title>
		<link>https://www.martinklinke.com/2016/06/01/how-to-generate-c-code-in-2016/</link>
		
		<dc:creator><![CDATA[Martin Klinke]]></dc:creator>
		<pubDate>Wed, 01 Jun 2016 21:15:21 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[tools]]></category>
		<guid isPermaLink="false">http://www.martinklinke.com/?p=117</guid>

					<description><![CDATA[Today I wanted to generate a bit of rather trivial C# code to provide a convenient facade to an internal library. After creating a T4 template, loadingÂ the required assembly and adding some namespace imports,Â I found it rather inefficientÂ to write code in that simple text editor without IntelliSense. So of course, there is always the option [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Today I wanted to generate a bit of rather trivial C# code to provide a convenient facade to an internal library. After creating a <a href="https://msdn.microsoft.com/en-us/library/bb126445.aspx">T4 template</a>, loadingÂ the required assembly and adding some namespace imports,Â I found it rather inefficientÂ to write code in that simple text editor without IntelliSense. So of course, there is always the option to write a code generator class with a method that returns a string. The T4 template can instantiate that class, call the method and emit the value directly:</p>
<blockquote><p>&lt;#= new CodeGenerator().Generate() #&gt;</p></blockquote>
<p>Next comes the question of how to implement the generator. StringBuilder? Come on, there must be a better way. I checked in another library that I knew was using code generation. Then IÂ sawÂ thatÂ the library was usingÂ <a href="https://msdn.microsoft.com/en-us/library/y2k85ax6(v=vs.110).aspx">CodeDOM</a>. For my simple needs, I decided that this would be sufficient for the time being (and efficient, since I didn&#8217;t want to spend too much time there).</p>
<p>But then I started toÂ wonder. WillÂ CodeDOMÂ still work with the newÂ <a href="https://dotnet.github.io/">.NET Core</a>?</p>
<p><span id="more-117"></span></p>
<p>The answer was <a href="http://stackoverflow.com/questions/7852926/microsoft-roslyn-vs-codedom">no</a>.</p>
<p>The linked StackOverflow question already includes the &#8220;replacement&#8221; of CodeDOM (CodeDOM is referred to as someÂ precursor to part of what Roslyn does): The &#8220;new&#8221; <a href="https://github.com/dotnet/roslyn">Roslyn compiler platform</a> (which has been around for a while by now). More specifically, the <a href="https://johnkoerner.com/csharp/creating-code-using-the-syntax-factory/">SyntaxFactory</a>Â that comes with Roslyn.</p>
<p>The only draw-back I see immediately: The code that uses the SyntaxFactoryÂ seemsÂ a lot more verbose than the CodeDOM API. On the plus side, theÂ Roslyn way should beÂ superior toÂ CodeDOM regarding features and support for language constructs.</p>
<p>There are already articlesÂ available for <a href="https://dogschasingsquirrels.com/2014/07/16/generating-code-with-roslyn/">generating code with Roslyn</a>, so I will leave the details to the interested reader.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
