<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Channel 9 Forums - Tech Off - Static initializers and reflection</title>
	<atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Forums/rss"></atom:link>
	<image>
		<url>http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.png</url>
		<title>Channel 9 Forums - Tech Off - Static initializers and reflection</title>
		<link>http://channel9.msdn.com/Forums</link>
	</image>
	<description>Channel 9 keeps you up to date with the latest news and behind the scenes info from Microsoft that developers love to keep up with. From LINQ to SilverLight – Watch videos and hear about all the cool technologies coming and the people behind them.</description>
	<link>http://channel9.msdn.com/Forums</link>
	<language>en</language>
	<pubDate>Sun, 26 May 2013 08:42:03 GMT</pubDate>
	<lastBuildDate>Sun, 26 May 2013 08:42:03 GMT</lastBuildDate>
	<generator>Rev9</generator>
	<c9:totalResults>8</c9:totalResults>
	<c9:pageCount>-8</c9:pageCount>
	<c9:pageSize>-1</c9:pageSize>
	<item>
		<title>Tech Off - Static initializers and reflection</title>
		<description><![CDATA[<p>So if you have a class that contains static fields, there is a static method that gets called to initialize these fields at startup (before any class instances are created). If you look at the IL, the method looks like this:</p><p><pre class="brush: text">  .method private hidebysig specialname rtspecialname static 
          void  .cctor() cil managed
  {
    // Code size       11 (0xb)
    .maxstack  8
    .line 25,25 : 9,42 ''
    IL_0000:  ldc.i4     0x3039
    IL_0005:  stsfld     int32 TestIL.TestClass1::m_int
    .line 16707566,16707566 : 0,0 ''
    IL_000a:  ret
  } // end of method TestClass1::.cctor</pre></p><p>My question is, how can one get this method via reflection at runtime?</p><p>&nbsp;</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/Static-initializers-and-reflection/1ae53cc3074b4138ae859f11012d77f7#1ae53cc3074b4138ae859f11012d77f7</link>
		<pubDate>Wed, 29 Jun 2011 18:17:36 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/Static-initializers-and-reflection/1ae53cc3074b4138ae859f11012d77f7#1ae53cc3074b4138ae859f11012d77f7</guid>
		<dc:creator>BitFlipper</dc:creator>
		<slash:comments>8</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/BitFlipper/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Static initializers and reflection</title>
		<description><![CDATA[<p>You can use Type.GetConstructors(BindingFlags.Static&nbsp;| BindingFlags.NonPublic) and select the one where IsStatic is true.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/Static-initializers-and-reflection/398075eeb8f74e2bb1259f1101313bf3#398075eeb8f74e2bb1259f1101313bf3</link>
		<pubDate>Wed, 29 Jun 2011 18:31:19 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/Static-initializers-and-reflection/398075eeb8f74e2bb1259f1101313bf3#398075eeb8f74e2bb1259f1101313bf3</guid>
		<dc:creator>Dexter</dc:creator>
		<slash:comments>8</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Dexter/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Static initializers and reflection</title>
		<description><![CDATA[<p></p><blockquote><div class="quoteText"><p></p><p><a class="permalink" title="Post Permalink" href="/Forums/TechOff/Static-initializers-and-reflection/398075eeb8f74e2bb1259f1101313bf3">6 minutes&nbsp;ago</a>,<a href="/Niners/Dexter">Dexter</a> wrote</p><p>You can use Type.GetConstructors(BindingFlags.Static&nbsp;| BindingFlags.NonPublic) and select the one where IsStatic is true.</p><p></p></div></blockquote><p></p><p>Ah excellent! I thought I tried that already, but I just tried it again and got it working.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/Static-initializers-and-reflection/a2362192e0454e80928a9f11013e602c#a2362192e0454e80928a9f11013e602c</link>
		<pubDate>Wed, 29 Jun 2011 19:19:10 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/Static-initializers-and-reflection/a2362192e0454e80928a9f11013e602c#a2362192e0454e80928a9f11013e602c</guid>
		<dc:creator>BitFlipper</dc:creator>
		<slash:comments>8</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/BitFlipper/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Static initializers and reflection</title>
		<description><![CDATA[<p>A related question...</p><p>Let's say I'm writing a compiler that takes IL and compiles it to some native code. At runtime, would it be enough to call all static contructors of all classes to ensure that static fields are properly initialized (does order matter?), or is there something else that needs to be executed as well (in addition to the assembly's EntryPoint)?</p><p>So basically:</p><ol><li>Call all static constructors </li><li>Call Assembly.EntryPoint </li></ol>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/Static-initializers-and-reflection/4a04cb95d0b044ceadef9f11013f89de#4a04cb95d0b044ceadef9f11013f89de</link>
		<pubDate>Wed, 29 Jun 2011 19:23:24 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/Static-initializers-and-reflection/4a04cb95d0b044ceadef9f11013f89de#4a04cb95d0b044ceadef9f11013f89de</guid>
		<dc:creator>BitFlipper</dc:creator>
		<slash:comments>8</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/BitFlipper/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Static initializers and reflection</title>
		<description><![CDATA[<p>Calling all static constructors before calling entry point can be inefficient if there are a lot of them. More importantly, if you want to call all static constructors at startup you'll find that there's no particular ordering you can use.</p><p>The basic requirement is that the static constructor (aka type initialized) of a type is called before any of the static fields of that type are accessed. This lazy initialization&nbsp;generates a particular ordering that you cannot reproduce at statup without some complicated or even impossible code analysis.</p><p>You can read more details about this in section 10.5.3 of the ECMA-335 standard (<a href="http://www.ecma-international.org/publications/standards/Ecma-335.htm">http://www.ecma-international.org/publications/standards/Ecma-335.htm</a>).</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/Static-initializers-and-reflection/2ccdbeb0c5ff49a3b4339f11014d3b49#2ccdbeb0c5ff49a3b4339f11014d3b49</link>
		<pubDate>Wed, 29 Jun 2011 20:13:15 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/Static-initializers-and-reflection/2ccdbeb0c5ff49a3b4339f11014d3b49#2ccdbeb0c5ff49a3b4339f11014d3b49</guid>
		<dc:creator>Dexter</dc:creator>
		<slash:comments>8</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Dexter/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Static initializers and reflection</title>
		<description><![CDATA[<p>@<a href="/Forums/TechOff/Static-initializers-and-reflection#c2ccdbeb0c5ff49a3b4339f11014d3b49">Dexter</a>:</p><p>In my case the number of static fields will be minimal so I don't think it should be a problem to just call them all.</p><p>Although, this lazy initialization... How would that work in cases like this:</p><p><pre class="brush: csharp">private static DateTime initTime =  DateTime.Now;</pre></p><p>...or cases where the static field is something that does real work, like a class that creates a file in its constructor, etc? Some other class instance might need to use that file. A bit of a contrived example, but still...</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/Static-initializers-and-reflection/c6384afc38c446f28abf9f11015a4bc1#c6384afc38c446f28abf9f11015a4bc1</link>
		<pubDate>Wed, 29 Jun 2011 21:00:49 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/Static-initializers-and-reflection/c6384afc38c446f28abf9f11015a4bc1#c6384afc38c446f28abf9f11015a4bc1</guid>
		<dc:creator>BitFlipper</dc:creator>
		<slash:comments>8</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/BitFlipper/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Static initializers and reflection</title>
		<description><![CDATA[<p>@<a href="/Forums/TechOff/Static-initializers-and-reflection#cc6384afc38c446f28abf9f11015a4bc1">BitFlipper</a>: Those cases are the developer's problem. Since the specification doesn't require that all static ctors are called at startup it's obvious that one should not depend on such behavior.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/Static-initializers-and-reflection/4b6a3339043e4068b8939f1200628734#4b6a3339043e4068b8939f1200628734</link>
		<pubDate>Thu, 30 Jun 2011 05:58:43 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/Static-initializers-and-reflection/4b6a3339043e4068b8939f1200628734#4b6a3339043e4068b8939f1200628734</guid>
		<dc:creator>Dexter</dc:creator>
		<slash:comments>8</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Dexter/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Static initializers and reflection</title>
		<description><![CDATA[<p>@<a href="/Forums/TechOff/Static-initializers-and-reflection#c4b6a3339043e4068b8939f1200628734">Dexter</a>:</p><p>OK thanks, that makes sense. Basically it is a non-issue.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/Static-initializers-and-reflection/35a9bc7708014dbea3f09f1200f216b4#35a9bc7708014dbea3f09f1200f216b4</link>
		<pubDate>Thu, 30 Jun 2011 14:41:25 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/Static-initializers-and-reflection/35a9bc7708014dbea3f09f1200f216b4#35a9bc7708014dbea3f09f1200f216b4</guid>
		<dc:creator>BitFlipper</dc:creator>
		<slash:comments>8</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/BitFlipper/Discussions/RSS</wfw:commentRss>
	</item>
</channel>
</rss>