<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Tags/Static Constructor on Emad Alashi</title>
    <link>https://emadashi.com/tags/static-constructor/</link>
    <description>Recent content in Tags/Static Constructor on Emad Alashi</description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Fri, 06 Feb 2009 22:39:22 +0000</lastBuildDate>
    <atom:link href="https://emadashi.com/tags/static-constructor/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Beware of Static Constructors</title>
      <link>https://emadashi.com/2009/02/be-ware-of-static-constructors/</link>
      <pubDate>Fri, 06 Feb 2009 22:39:22 +0000</pubDate>
      <guid>https://emadashi.com/2009/02/be-ware-of-static-constructors/</guid>
      <description>&lt;p&gt;In &lt;a href=&#34;http://www.codeplex.com/bunian&#34;&gt;Bunian&lt;/a&gt; we needed to use a static constructor for some reason, it was all going good; we tested the code and it ran smoothly…excellent (&lt;a href=&#34;http://en.wikipedia.org/wiki/Code_coverage&#34;&gt;Code Coverage&lt;/a&gt; anyone?!).&lt;br&gt;
But when I came across this situation, it appeared that the static constructor wasn&amp;rsquo;t invoked!even when “Class.Method();” is called! so lets examine it.&lt;/p&gt;
&lt;p&gt;I have two simple classes as an Example:&lt;/p&gt;
&lt;div style=&#34;font-size:10pt;background:#f2ebe3;color:black;font-family:courier new;&#34;&gt;
  &lt;p style=&#34;margin:0;&#34;&gt;
    &lt;span style=&#34;color:blue;&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:blue;&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#2b91af;&#34;&gt;Parent&lt;/span&gt;
  &lt;/p&gt;
  &lt;p style=&#34;margin:0;&#34;&gt;
    {
  &lt;/p&gt;
  &lt;p style=&#34;margin:0;&#34;&gt;
        &lt;span style=&#34;color:blue;&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:blue;&#34;&gt;static&lt;/span&gt; &lt;span style=&#34;color:blue;&#34;&gt;string&lt;/span&gt; DoSomething()
  &lt;/p&gt;
  &lt;p style=&#34;margin:0;&#34;&gt;
        {
  &lt;/p&gt;
  &lt;p style=&#34;margin:0;&#34;&gt;
            &lt;span style=&#34;color:blue;&#34;&gt;return&lt;/span&gt; &lt;span style=&#34;color:#a31515;&#34;&gt;“Parent: DoSomething() called”&lt;/span&gt;;
  &lt;/p&gt;
  &lt;p style=&#34;margin:0;&#34;&gt;
        }
  &lt;/p&gt;
  &lt;p style=&#34;margin:0;&#34;&gt;
    }
  &lt;/p&gt;
&lt;/div&gt;
&lt;div style=&#34;font-size:10pt;background:#f2ebe3;color:black;font-family:courier new;&#34;&gt;
  &lt;p style=&#34;margin:0;&#34;&gt;
    &lt;span style=&#34;color:blue;&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:blue;&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#2b91af;&#34;&gt;Child&lt;/span&gt; : Parent
  &lt;/p&gt;
  &lt;p style=&#34;margin:0;&#34;&gt;
    {
  &lt;/p&gt;</description>
    </item>
  </channel>
</rss>
