<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>C# on Design Principia</title>
		<link>https://designprincipia.com/categories/c%23/</link>
		<description>Recent content in C# on Design Principia</description>
		<generator>Hugo</generator>
		<language>en-us</language>
		
		
		
		
			<lastBuildDate>Thu, 02 Sep 2021 05:18:44 +0000</lastBuildDate>
		
			<atom:link href="https://designprincipia.com/categories/c%23/index.xml" rel="self" type="application/rss+xml" />
			<item>
				<title>Analyzing .NET managed code profile along with external code</title>
				<link>https://designprincipia.com/post/profiling-net-managed-code-along-with-external-code/</link>
				<pubDate>Thu, 02 Sep 2021 05:18:44 +0000</pubDate>
				<guid>https://designprincipia.com/post/profiling-net-managed-code-along-with-external-code/</guid>
				<description>How to analyze external code high CPU usage in .NET applications</description>
			</item>
			<item>
				<title>.NET IDisposable implementation</title>
				<link>https://designprincipia.com/post/idisposable-implementation-and-who-should-call-it/</link>
				<pubDate>Mon, 26 Feb 2018 04:02:58 +0000</pubDate>
				<guid>https://designprincipia.com/post/idisposable-implementation-and-who-should-call-it/</guid>
				<description>&lt;p&gt;The other day I got a code review comment saying that I should implement the &lt;a href=&#34;https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-dispose&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;full blown disposable pattern for IDisposable&lt;/a&gt; including the &lt;code&gt;protected virtual void Dispose(bool disposing)&lt;/code&gt; method. For a long time I had implemented the &lt;em&gt;IDisposable&lt;/em&gt; without caring about the additional overload - and I started worrying how many bugs I&amp;rsquo;ve introduced by not doing so.&lt;/p&gt;&#xA;&lt;h2 id=&#34;the-pattern&#34;&gt;The pattern&lt;/h2&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-dispose&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;The most recent official documentation I could find&lt;/a&gt; describes the pattern in details, which I&amp;rsquo;ll summarize below.&lt;/p&gt;</description>
			</item>
			<item>
				<title>The interface not supported fallacy</title>
				<link>https://designprincipia.com/post/the-interface-not-supported-fallacy/</link>
				<pubDate>Sat, 20 Jan 2018 09:37:19 +0000</pubDate>
				<guid>https://designprincipia.com/post/the-interface-not-supported-fallacy/</guid>
				<description>&lt;p&gt;Today I was reviewing a colleague&amp;rsquo;s code and I saw a pattern similar to the one below:&lt;/p&gt;</description>
			</item>
			<item>
				<title>Default property value when serializing with Newtonsoft JSON</title>
				<link>https://designprincipia.com/post/newtonsoft-serialize-with-default-value/</link>
				<pubDate>Fri, 09 Jun 2017 12:13:07 +0000</pubDate>
				<guid>https://designprincipia.com/post/newtonsoft-serialize-with-default-value/</guid>
				<description>&lt;p&gt;The other day I wanted to use Newtonsoft JSON serializer to convert objects to JSON   strings, with the twist that if some property of the object was &lt;em&gt;null&lt;/em&gt; it should be defaulted to a specific value in the JSON string.&lt;/p&gt;&#xA;&lt;p&gt;There is the &lt;a href=&#34;http://www.newtonsoft.com/json/help/html/DefaultValueAttributeIgnore.htm&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;DefaultValueAttribute&lt;/a&gt; but that seems to work only for deserialization (or so it seemed when I gave up searching for an out of the box behavior).&lt;/p&gt;&#xA;&lt;p&gt;It turns out you can implement a &lt;a href=&#34;http://www.newtonsoft.com/json/help/html/ContractResolver.htm&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;ContractResolver&lt;/a&gt;. Inheriting from the base &lt;a href=&#34;http://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_Serialization_DefaultContractResolver.htm&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;DefaultContractResolver&lt;/a&gt; seems to be the easiest way to go. Then you can override just the &lt;em&gt;CreateProperty&lt;/em&gt; method and provide an instance of &lt;a href=&#34;http://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_Serialization_IValueProvider.htm&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;IValueProvider&lt;/a&gt; to the property contract generated by that method. Check out the example below.&lt;/p&gt;</description>
			</item>
	</channel>
</rss>
