<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" gd:etag="W/&quot;CEAGR3k-cSp7ImA9WxNUFEU.&quot;"><id>tag:blogger.com,1999:blog-8486822413101972100</id><updated>2009-11-06T09:45:26.759+05:00</updated><title>.NET tips, tricks and patterns</title><subtitle type="html">From well-known to unknown.</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://tips.x-tensive.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://tips.x-tensive.com/" /><link rel="hub" href="http://pubsubhubbub.appspot.com/" /><author><name>Alex Yakunin</name><uri>http://www.blogger.com/profile/13800929290476802273</uri><email>noreply@blogger.com</email></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>13</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><link rel="self" href="http://feeds.feedburner.com/dotNetTips" type="application/atom+xml" /><feedburner:emailServiceId xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">dotNetTips</feedburner:emailServiceId><feedburner:feedburnerHostname xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://feedburner.google.com</feedburner:feedburnerHostname><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><entry gd:etag="W/&quot;CEAGR3kycSp7ImA9WxNUFEU.&quot;"><id>tag:blogger.com,1999:blog-8486822413101972100.post-4915200485981210313</id><published>2009-11-06T09:45:00.001+05:00</published><updated>2009-11-06T09:45:26.799+05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-11-06T09:45:26.799+05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="functional programming" /><category scheme="http://www.blogger.com/atom/ns#" term="usability" /><category scheme="http://www.blogger.com/atom/ns#" term="extension methods" /><title>Currying in C#</title><content type="html">A &lt;a href="http://blog.alexyakunin.com/2009/09/currying-in-c.html"&gt;link to my post about currying in C#&lt;/a&gt; perfectly fits this blog.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8486822413101972100-4915200485981210313?l=tips.x-tensive.com'/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=0wbtxNZnkGI:GEWx0kgQiZ4:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=0wbtxNZnkGI:GEWx0kgQiZ4:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?i=0wbtxNZnkGI:GEWx0kgQiZ4:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=0wbtxNZnkGI:GEWx0kgQiZ4:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=0wbtxNZnkGI:GEWx0kgQiZ4:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?i=0wbtxNZnkGI:GEWx0kgQiZ4:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://tips.x-tensive.com/feeds/4915200485981210313/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://tips.x-tensive.com/2009/11/currying-in-c.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8486822413101972100/posts/default/4915200485981210313?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8486822413101972100/posts/default/4915200485981210313?v=2" /><link rel="alternate" type="text/html" href="http://tips.x-tensive.com/2009/11/currying-in-c.html" title="Currying in C#" /><author><name>Alex Yakunin</name><uri>http://www.blogger.com/profile/13800929290476802273</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="09650213915253068470" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></entry><entry gd:etag="W/&quot;AkAGRX4zfyp7ImA9WxJaF08.&quot;"><id>tag:blogger.com,1999:blog-8486822413101972100.post-5747249071466843072</id><published>2009-08-08T15:40:00.001+06:00</published><updated>2009-08-08T16:52:04.087+06:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-08-08T16:52:04.087+06:00</app:edited><title>Making IDisposable more usable, part 1</title><content type="html">&lt;p&gt;&lt;strong&gt;IDisposable&lt;/strong&gt; is used quite frequently, so here I’m going to provide few hacks allowing to improve its usability. First of all, let's create &lt;strong&gt;IDisposableExtensions&lt;/strong&gt; with a single method:&lt;/p&gt; &lt;pre style="background: black" class="code"&gt;&lt;span style="background: black; color: silver"&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;    /// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;Safely disposes an &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;IDisposable&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: green"&gt;object.&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;disposable&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;Object to dispose (can be &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;see langword=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;null&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;).&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public static void &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;DisposeSafely&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;this &lt;/span&gt;&lt;span style="background: black; color: #2b91af"&gt;IDisposable &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;disposable&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;    {&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;if &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;disposable&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;!=&lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;null&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;disposable&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Dispose&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;();&lt;br /&gt;    }&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;This gives us an ability to dispose the objects without repeating null-check:&lt;/p&gt;&lt;br /&gt;&lt;pre style="background: black" class="code"&gt;&lt;span style="background: black; color: silver"&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;try &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;{&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;writer&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;DisposeSafely&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;();&lt;br /&gt;    }&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;finally &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;{&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;writer &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;= &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;null&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;;&lt;br /&gt;    }&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Let's go further now. Frequently you must &lt;strong&gt;safely&lt;/strong&gt; dispose two or more &lt;strong&gt;IDisposable&lt;/strong&gt; objects. Note that &amp;quot;safely&amp;quot; is an essential word here. You can't write something like:&lt;/p&gt;&lt;br /&gt;&lt;pre style="background: black" class="code"&gt;&lt;span style="background: black; color: silver"&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;disposable1&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;DisposeSafely&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;();&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;disposable2&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;DisposeSafely&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;();&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;This code may fail: an exception can be thrown on execution of its first line, and if this happens, its second line won't be executed at all. So &lt;strong&gt;disposable2&lt;/strong&gt; has a chance of not being disposed. That's why it's a good idea to implement few helpers allowing us to deal with such issues safely.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Let's add &lt;strong&gt;JoiningDisposable&lt;/strong&gt; type:&lt;/p&gt;&lt;br /&gt;&lt;pre style="background: black" class="code"&gt;&lt;span style="background: black; color: silver"&gt;  &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;  /// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;Disposes two &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;IDisposable&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: green"&gt;objects.&lt;br /&gt;  &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;[&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Serializable&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;]&lt;br /&gt;  &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public sealed class &lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;JoiningDisposable &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;: &lt;/span&gt;&lt;span style="background: black; color: #2b91af"&gt;IDisposable&lt;br /&gt;  &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;{&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;private &lt;/span&gt;&lt;span style="background: black; color: #2b91af"&gt;IDisposable &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;first&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;private &lt;/span&gt;&lt;span style="background: black; color: #2b91af"&gt;IDisposable &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;second&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;    /// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;Gets the first object to dispose.&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public &lt;/span&gt;&lt;span style="background: black; color: #2b91af"&gt;IDisposable &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;First &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;{&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;get &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;{ &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;return &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;first&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;; }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;    /// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;Gets the second object to dispose.&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public &lt;/span&gt;&lt;span style="background: black; color: #2b91af"&gt;IDisposable &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Second &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;{&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;get &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;{ &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;return &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;second&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;; }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;    /// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;Joins the &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;JoiningDisposable&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: green"&gt;and &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;IDisposable&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;.&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;first&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The first disposable to join.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;second&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The second disposable to join.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    /// &amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;New &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;JoiningDisposable&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: green"&gt;that will&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;dispose both of them on its disposal&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/returns&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public static &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;JoiningDisposable &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;operator &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;amp;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;JoiningDisposable first&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #2b91af"&gt;IDisposable &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;second&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;    {&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;if &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;second&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;==&lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;null&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;return &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;first&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;;&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;return new &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;JoiningDisposable&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;first&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;second&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: green"&gt;// Constructors&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;    ///   &amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;ClassDocTemplate.Ctor&amp;quot; &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;copy=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;true&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt;&lt;br /&gt;    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;disposable1&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The first disposable.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;disposable2&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The second disposable.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;JoiningDisposable&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #2b91af"&gt;IDisposable &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;disposable1&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #2b91af"&gt;IDisposable &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;disposable2&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;    {&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;this&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;first &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;= &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;disposable1&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;;&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;this&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;second &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;= &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;disposable2&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;inheritdoc/&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public void &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Dispose&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;()&lt;br /&gt;    {&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;var &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;d1 &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;= &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;first&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;;&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;first &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;= &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;null&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;;&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;try &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;{&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;d1&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;DisposeSafely&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;();&lt;br /&gt;      }&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;catch &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;ex&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;) {&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;using &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;var &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;ea &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;= &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;new &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;ExceptionAggregator&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;()) {&lt;br /&gt;          &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;ea&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Execute&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;_this &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;=&amp;gt; {&lt;br /&gt;            &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;var &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;d2 &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;= &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;_this&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;second&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;;&lt;br /&gt;            &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;_this&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;second &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;= &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;null&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;;&lt;br /&gt;            &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;d2&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;DisposeSafely&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;();&lt;br /&gt;          }, &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;this&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;          &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;ea&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Execute&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;e &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;=&amp;gt; { &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;throw &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;e&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;; }, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;ex&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;        }&lt;br /&gt;      }&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;d1 &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;= &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;second&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;;&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;second &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;= &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;null&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;;&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;d1&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;DisposeSafely&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;();&lt;br /&gt;    }&lt;br /&gt;  }&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;As you see, the code in its &lt;strong&gt;Dispose&lt;/strong&gt; method relies on &lt;strong&gt;ExceptionAggregator&lt;/strong&gt;. Here it is:&lt;/p&gt;&lt;br /&gt;&lt;pre style="background: black" class="code"&gt;&lt;span style="background: black; color: silver"&gt;  &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;  /// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;Provides exception aggregation support.&lt;br /&gt;  &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;[&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Serializable&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;]&lt;br /&gt;  &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public class &lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;ExceptionAggregator &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;: &lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #2b91af"&gt;IDisposable&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;ICountable&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt;&lt;br /&gt;  {&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;private &lt;/span&gt;&lt;span style="background: black; color: #2b91af"&gt;Action&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptionHandler&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;private &lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;List&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;private string &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptionMessage&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;private bool &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;isDisposed &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;= &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;false&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;    /// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;Gets or sets the exception handler.&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public &lt;/span&gt;&lt;span style="background: black; color: #2b91af"&gt;Action&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;ExceptionHandler&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;{&lt;br /&gt;      [&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;DebuggerStepThrough&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;]&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;get &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;{ &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;return &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptionHandler&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;; }&lt;br /&gt;      [&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;DebuggerStepThrough&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;]&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;set &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;{ &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptionHandler &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;= &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;value&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;; }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;    /// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;Gets the number of caught exceptions.&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public long &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Count&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;{&lt;br /&gt;      [&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;DebuggerStepThrough&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;]&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;get &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;{ &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;return &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;!=&lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;null &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;? &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Count &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;: 0; }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #329997"&gt;#region &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;Execute(...) methods&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;    /// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;Executes the specified action catching all the exceptions from it,&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;adding it to internal list of caught exceptions and&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;and passing it to &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;ExceptionHandler&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: green"&gt;handler.&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;action&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The action to execute.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    /// &amp;lt;exception cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;ObjectDisposedException&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;Aggregator is already disposed.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/exception&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public void &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Execute&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Action action&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;    {&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;if &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;isDisposed&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;throw &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;AlreadyDisposed&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;null&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;try &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;{&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;action&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;();&lt;br /&gt;      }&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;catch &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;e&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;) {&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;HandleException&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;e&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;    /// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;Executes the specified action catching all the exceptions from it,&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;adding it to internal list of caught exceptions and&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;and passing it to &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;ExceptionHandler&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: green"&gt;handler.&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;    /// &amp;lt;typeparam name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;T&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The type of action argument.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/typeparam&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;action&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The action to execute.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;argument&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The action argument value.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    /// &amp;lt;exception cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;ObjectDisposedException&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;Aggregator is already disposed.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/exception&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public void &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Execute&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt;(&lt;/span&gt;&lt;span style="background: black; color: #2b91af"&gt;Action&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;action&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T argument&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;    {&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;if &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;isDisposed&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;throw &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;AlreadyDisposed&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;null&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;try &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;{&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;action&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;argument&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;      }&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;catch &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;e&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;) {&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;HandleException&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;e&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;    /// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;Executes the specified action catching all the exceptions from it,&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;adding it to internal list of caught exceptions and&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;and passing it to &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;ExceptionHandler&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: green"&gt;handler.&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;    /// &amp;lt;typeparam name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;T1&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The type of the 1st action argument.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/typeparam&amp;gt;&lt;br /&gt;    /// &amp;lt;typeparam name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;T2&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The type of the 2nd action argument.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/typeparam&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;action&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The action to execute.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;argument1&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The 1st action argument value.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;argument2&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The 2nd action argument value.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    /// &amp;lt;exception cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;ObjectDisposedException&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;Aggregator is already disposed.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/exception&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public void &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Execute&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T1&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T2&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Action&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T1&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T2&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;action&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T1 argument1&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T2 argument2&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;    {&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;if &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;isDisposed&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;throw &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;AlreadyDisposed&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;null&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;try &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;{&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;action&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;argument1&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;argument2&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;      }&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;catch &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;e&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;) {&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;HandleException&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;e&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;    /// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;Executes the specified action catching all the exceptions from it,&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;adding it to internal list of caught exceptions and&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;and passing it to &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;ExceptionHandler&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: green"&gt;handler.&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;    /// &amp;lt;typeparam name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;T1&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The type of the 1st action argument.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/typeparam&amp;gt;&lt;br /&gt;    /// &amp;lt;typeparam name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;T2&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The type of the 2nd action argument.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/typeparam&amp;gt;&lt;br /&gt;    /// &amp;lt;typeparam name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;T3&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The type of the 3rd action argument.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/typeparam&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;action&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The action to execute.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;argument1&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The 1st action argument value.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;argument2&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The 2nd action argument value.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;argument3&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The 3rd action argument value.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    /// &amp;lt;exception cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;ObjectDisposedException&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;Aggregator is already disposed.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/exception&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public void &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Execute&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T1&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T2&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T3&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Action&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T1&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T2&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T3&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;action&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T1 argument1&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T2 argument2&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T3 argument3&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;    {&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;if &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;isDisposed&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;throw &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;AlreadyDisposed&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;null&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;try &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;{&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;action&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;argument1&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;argument2&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;argument3&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;      }&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;catch &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;e&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;) {&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;HandleException&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;e&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;    /// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;Executes the specified function catching all the exceptions from it,&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;adding it to internal list of caught exceptions and&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;and passing it to &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;ExceptionHandler&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: green"&gt;handler.&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;    /// &amp;lt;typeparam name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;TResult&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The type of function result.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/typeparam&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;function&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The function to execute.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    /// &amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;Function execution result, if no exception was caught;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;otherwise, &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;see langword=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;default(TResult)&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/returns&amp;gt;&lt;br /&gt;    /// &amp;lt;exception cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;ObjectDisposedException&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;Aggregator is already disposed.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/exception&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;TResult Execute&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;TResult&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Func&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;TResult&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;function&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;    {&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;if &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;isDisposed&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;throw &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;AlreadyDisposed&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;null&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;try &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;{&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;return &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;function&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;();&lt;br /&gt;      }&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;catch &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;e&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;) {&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;HandleException&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;e&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;      }&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;return default&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;TResult&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;    /// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;Executes the specified function catching all the exceptions from it,&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;adding it to internal list of caught exceptions and&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;and passing it to &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;ExceptionHandler&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: green"&gt;handler.&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;    /// &amp;lt;typeparam name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;T&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The type of the function argument.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/typeparam&amp;gt;&lt;br /&gt;    /// &amp;lt;typeparam name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;TResult&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The type of function result.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/typeparam&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;function&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The function to execute.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;argument&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The function argument value.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    /// &amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;Function execution result, if no exception was caught;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;otherwise, &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;see langword=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;default(TResult)&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/returns&amp;gt;&lt;br /&gt;    /// &amp;lt;exception cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;ObjectDisposedException&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;Aggregator is already disposed.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/exception&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;TResult Execute&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;TResult&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Func&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;TResult&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;function&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T argument&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;    {&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;if &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;isDisposed&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;throw &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;AlreadyDisposed&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;null&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;try &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;{&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;return &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;function&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;argument&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;      }&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;catch &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;e&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;) {&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;HandleException&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;e&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;      }&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;return default&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;TResult&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;    /// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;Executes the specified function catching all the exceptions from it,&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;adding it to internal list of caught exceptions and&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;and passing it to &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;ExceptionHandler&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: green"&gt;handler.&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;    /// &amp;lt;typeparam name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;T1&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The type of the 1st function argument.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/typeparam&amp;gt;&lt;br /&gt;    /// &amp;lt;typeparam name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;T2&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The type of the 2nd function argument.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/typeparam&amp;gt;&lt;br /&gt;    /// &amp;lt;typeparam name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;TResult&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The type of function result.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/typeparam&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;function&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The function to execute.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;argument1&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The 1st function argument value.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;argument2&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The 2nd function argument value.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    /// &amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;Function execution result, if no exception was caught;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;otherwise, &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;see langword=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;default(TResult)&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/returns&amp;gt;&lt;br /&gt;    /// &amp;lt;exception cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;ObjectDisposedException&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;Aggregator is already disposed.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/exception&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;TResult Execute&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T1&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T2&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;TResult&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Func&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T1&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T2&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;TResult&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;function&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T1 argument1&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T2 argument2&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;    {&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;if &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;isDisposed&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;throw &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;AlreadyDisposed&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;null&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;try &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;{&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;return &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;function&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;argument1&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;argument2&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;      }&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;catch &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;e&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;) {&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;HandleException&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;e&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;      }&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;return default&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;TResult&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;    /// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;Executes the specified function catching all the exceptions from it,&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;adding it to internal list of caught exceptions and&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;and passing it to &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;ExceptionHandler&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: green"&gt;handler.&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;    /// &amp;lt;typeparam name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;T1&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The type of the 1st function argument.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/typeparam&amp;gt;&lt;br /&gt;    /// &amp;lt;typeparam name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;T2&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The type of the 2nd function argument.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/typeparam&amp;gt;&lt;br /&gt;    /// &amp;lt;typeparam name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;T3&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The type of the 3rd function argument.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/typeparam&amp;gt;&lt;br /&gt;    /// &amp;lt;typeparam name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;TResult&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The type of function result.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/typeparam&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;function&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The function to execute.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;argument1&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The 1st function argument value.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;argument2&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The 2nd function argument value.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;argument3&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The 3rd function argument value.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    /// &amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;Function execution result, if no exception was caught;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;otherwise, &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;see langword=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;default(TResult)&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/returns&amp;gt;&lt;br /&gt;    /// &amp;lt;exception cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;ObjectDisposedException&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;Aggregator is already disposed.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/exception&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;TResult Execute&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T1&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T2&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T3&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;TResult&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Func&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T1&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T2&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T3&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;TResult&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;function&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T1 argument1&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T2 argument2&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;T3 argument3&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;    {&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;if &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;isDisposed&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;throw &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;AlreadyDisposed&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;null&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;try &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;{&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;return &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;function&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;argument1&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;argument2&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;argument3&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;      }&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;catch &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;e&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;) {&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;HandleException&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;e&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;      }&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;return default&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;TResult&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #329997"&gt;#endregion&lt;br /&gt;&lt;br /&gt;    #region &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;IEnumerable&amp;lt;...&amp;gt; methods&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;inheritdoc/&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;[&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;DebuggerStepThrough&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;]&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #2b91af"&gt;IEnumerator IEnumerable&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;GetEnumerator&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;()&lt;br /&gt;    {&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;return &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;GetEnumerator&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;inheritdoc/&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public &lt;/span&gt;&lt;span style="background: black; color: #2b91af"&gt;IEnumerator&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;GetEnumerator&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;()&lt;br /&gt;    {&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;if &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;==&lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;null&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;return &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;EnumerableUtils&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;EmptyEnumerator&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;;&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;else &lt;br /&gt;        return &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;GetEnumerator&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #329997"&gt;#endregion&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;    /// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;Invoked on any exception caught by &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;Execute&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: green"&gt;methods.&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;exception&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The caught exception.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    /// &amp;lt;remarks&amp;gt;&lt;br /&gt;    /// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;If this method throws an exception, it won't be caught.&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;I.e. it will throw &amp;quot;through&amp;quot; any of &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;Execute&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: green"&gt;methods.&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;/remarks&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;protected virtual void &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;HandleException&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;    {&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;if &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptionHandler&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;!=&lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;null&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptionHandler&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;if &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;==&lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;null&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptions &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;= &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;new &lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;List&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt;();&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Add&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: green"&gt;// Constructors&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;    /// &amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;ClassDocTemplate.Ctor&amp;quot; &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;copy=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;true&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt;&lt;br /&gt;    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;ExceptionAggregator&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;()&lt;br /&gt;      : &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;this&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;null&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;null&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;    {&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;    /// &amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;ClassDocTemplate.Ctor&amp;quot; &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;copy=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;true&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt;&lt;br /&gt;    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;exceptionMessage&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The message of &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;AggregateException&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;ExceptionAggregator&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;string &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptionMessage&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;      : &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;this &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;null&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptionMessage&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;    {&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;    /// &amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;ClassDocTemplate.Ctor&amp;quot; &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;copy=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;true&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt;&lt;br /&gt;    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;exceptionHandler&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The exception handler.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;exceptionMessage&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The message of &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;AggregateException&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;ExceptionAggregator&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #2b91af"&gt;Action&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptionHandler&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;string &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptionMessage&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;    {&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;this&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptionHandler &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;= &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptionHandler&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;;&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;this&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptionMessage &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;= &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptionMessage&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: green"&gt;// Descructor&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;ClassDocTemplate.Dispose&amp;quot; &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;copy=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;true&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt;&lt;br /&gt;    /// &amp;lt;exception cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;AggregateException&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;Thrown if at least one exception was caught &lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;by &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;Execute&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: green"&gt;methods.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/exception&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public void &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Dispose&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;()&lt;br /&gt;    {&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;if &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;!=&lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;null &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Count&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt;0) {&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exception &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;= &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;string&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;IsNullOrEmpty&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptionMessage&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;) ? &lt;br /&gt;          &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;new &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;AggregateException&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;) : &lt;br /&gt;          &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;new &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;AggregateException&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptionMessage&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);        &lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptions &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;= &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;null&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;;&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;isDisposed &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;= &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;true&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;;&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;throw &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;;&lt;br /&gt;      }&lt;br /&gt;    }&lt;br /&gt;  }&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Finally, both these types use &lt;strong&gt;AggregateException&lt;/strong&gt;:&lt;/p&gt;&lt;br /&gt;&lt;pre style="background: black" class="code"&gt;&lt;span style="background: black; color: silver"&gt;  &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;  /// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;Aggregates a set of caught exceptions.&lt;br /&gt;  &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;  &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;[&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Serializable&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;]&lt;br /&gt;  &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public class &lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;AggregateException &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;: &lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;,&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;IHasExceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt;&lt;br /&gt;  {&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;private &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;ReadOnlyList&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;    /// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;Gets the list of caught exceptions.&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;ReadOnlyList&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Exceptions&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;{&lt;br /&gt;      [&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;DebuggerStepThrough&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;]&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;get &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;{ &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;return &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;; }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;inheritdoc/&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #2b91af"&gt;IEnumerable&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;IHasExceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Exceptions&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;{&lt;br /&gt;      [&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;DebuggerStepThrough&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;]&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;get &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;{ &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;return &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;; }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;inheritdoc/&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #2b91af"&gt;IEnumerable&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;IHasExceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Exceptions&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;{&lt;br /&gt;      [&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;DebuggerStepThrough&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;]&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;get &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;{ &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;return &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;; }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;    /// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;Gets the &amp;quot;flat&amp;quot; list with all aggregated exceptions. &lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;If other &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot; AggregateException&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;s were aggregated, &lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;their inner exceptions are included instead of them.&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;    /// &amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;Flat list of aggregated exceptions.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/returns&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public &lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;List&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;GetFlatExceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;()&lt;br /&gt;    {&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;var &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;result &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;= &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;new &lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;List&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt;();&lt;br /&gt;&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;foreach &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;var &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exception &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;in &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;) {&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;var &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;ae &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;= &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exception &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;as &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;AggregateException&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;;&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;if &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;ae&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;!=&lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;null&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;          &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;result&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;AddRange&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;ae&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;GetFlatExceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;());&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;else&lt;br /&gt;          &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;result&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Add&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;return &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;result&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;inheritdoc/&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public override string &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;ToString&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;()&lt;br /&gt;    {&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;StringBuilder &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;sb &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;= &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;new &lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;StringBuilder&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(64);&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;sb&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Append&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;base&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;ToString&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;());&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;sb&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;AppendFormat&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: cyan"&gt;&amp;quot;\r\n{0}:&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Strings&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;OriginalExceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;int &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;i &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;= 1;&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;foreach &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exception &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;in &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;        &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;sb&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;AppendFormat&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: cyan"&gt;&amp;quot;\r\n{0}: {1}&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;i&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;++, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;return &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;sb&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;ToString&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #329997"&gt;#region &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;Private \ internal methods&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;private void &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;SetExceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #2b91af"&gt;IEnumerable&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;    {&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;var &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;list &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;= &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptions &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;as &lt;/span&gt;&lt;span style="background: black; color: #2b91af"&gt;IList&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt; ?? &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;ToList&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;();&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;this&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptions &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;= &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;new &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;ReadOnlyList&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;list&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;private void &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;SetExceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;    {&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;var &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;list &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;= &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;new &lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;List&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt;();&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;list&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Add&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptions &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;= &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;new &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;ReadOnlyList&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;list&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #329997"&gt;#endregion&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: green"&gt;// Constructors&lt;br /&gt;    &lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;    /// &amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;ClassDocTemplate.Ctor&amp;quot; &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;copy=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;true&amp;quot; &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt;&lt;br /&gt;    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;AggregateException&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;()&lt;br /&gt;      : &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;base&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Strings&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;ExASetOfExceptionsIsCaught&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;    {&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;    /// &amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;ClassDocTemplate.Ctor&amp;quot; &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;copy=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;true&amp;quot; &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt;&lt;br /&gt;    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;text&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;Text of message.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;AggregateException&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;string &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;text&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;      : &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;base&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;text&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;    {&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;    /// &amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;ClassDocTemplate.Ctor&amp;quot; &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;copy=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;true&amp;quot; &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt;&lt;br /&gt;    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;message&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;Text of message.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;innerException&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;Inner exception.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;AggregateException&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;string &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;message&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;innerException&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;) &lt;br /&gt;      : &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;base&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;message&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;innerException&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;    {&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;SetExceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;innerException&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;    /// &amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;ClassDocTemplate.Ctor&amp;quot; &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;copy=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;true&amp;quot; &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt;&lt;br /&gt;    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;exceptions&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;Inner exceptions.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;AggregateException&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #2b91af"&gt;IEnumerable&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;) &lt;br /&gt;      : &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;base&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;Strings&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;ExASetOfExceptionsIsCaught&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;First&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;())&lt;br /&gt;    {&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;SetExceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;    /// &amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;ClassDocTemplate.Ctor&amp;quot; &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;copy=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;true&amp;quot; &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt;&lt;br /&gt;    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;message&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;Text of message.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;exceptions&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;Inner exceptions.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;AggregateException&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;string &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;message&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #2b91af"&gt;IEnumerable&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;) &lt;br /&gt;      : &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;base&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;message&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;First&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;())&lt;br /&gt;    {&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;SetExceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: green"&gt;// Serialization&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;SerializableDocTemplate.Ctor&amp;quot; &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;copy=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;true&amp;quot; &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;protected &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;AggregateException&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;SerializationInfo &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;info&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #2b91af"&gt;StreamingContext &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;context&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;      : &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;base&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;info&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;context&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;    {&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptions &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;= (&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;ReadOnlyList&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt;)&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;info&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;GetValue&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: cyan"&gt;&amp;quot;Exceptions&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;typeof &lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;ReadOnlyList&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;Exception&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;&amp;gt;));&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;SerializableDocTemplate.GetObjectData&amp;quot; &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;copy=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;true&amp;quot; &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public override void &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;GetObjectData&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #999655"&gt;SerializationInfo &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;info&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #2b91af"&gt;StreamingContext &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;context&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;    {&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;base&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;GetObjectData&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;info&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;context&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;info&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;.&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;AddValue&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: cyan"&gt;&amp;quot;Exceptions&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;exceptions&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;    }&lt;br /&gt;  }&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;And now we're going to the final step. Let's add one more extension method to our &lt;strong&gt;DisposableExtensions&lt;/strong&gt;:&lt;/p&gt;&lt;br /&gt;&lt;pre style="background: black" class="code"&gt;&lt;span style="background: black; color: silver"&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;    /// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;Joins the specified disposable objects by returning&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;a single &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;JoiningDisposable&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: green"&gt;that will&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;dispose both of them on its disposal.&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &amp;lt;/summary&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;disposable&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The first disposable.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    /// &amp;lt;param name=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;joinWith&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;The second disposable.&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;    /// &amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="background: black; color: green"&gt;New &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;see cref=&lt;/span&gt;&lt;span style="background: black; color: #646464"&gt;&amp;quot;JoiningDisposable&amp;quot;&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/&amp;gt; &lt;/span&gt;&lt;span style="background: black; color: green"&gt;that will&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: gray"&gt;/// &lt;/span&gt;&lt;span style="background: black; color: green"&gt;dispose both of them on its disposal&lt;/span&gt;&lt;span style="background: black; color: gray"&gt;&amp;lt;/returns&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;public static &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;JoiningDisposable Join&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;this &lt;/span&gt;&lt;span style="background: black; color: #2b91af"&gt;IDisposable &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;disposable&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #2b91af"&gt;IDisposable &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;joinWith&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;)&lt;br /&gt;    {&lt;br /&gt;      &lt;/span&gt;&lt;span style="background: black; color: #ff9428"&gt;return new &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;JoiningDisposable&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;(&lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;disposable&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;, &lt;/span&gt;&lt;span style="background: black; color: #ffcb00"&gt;joinWith&lt;/span&gt;&lt;span style="background: black; color: silver"&gt;);&lt;br /&gt;    }&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;When this is done, you can use the following code with &lt;strong&gt;Join&lt;/strong&gt; to safely dispose two or more &lt;strong&gt;IDisposable&lt;/strong&gt;s:&lt;/p&gt;&lt;br /&gt;&lt;pre class="code" style="background: black;"&gt;&lt;span style="color:silver;background:black"&gt;    &lt;/span&gt;&lt;span style="color:gray;background:black"&gt;/// &amp;lt;inheritdoc/&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color:silver;background:black"&gt;[&lt;/span&gt;&lt;span style="color:#999655;background:black"&gt;DebuggerStepThrough&lt;/span&gt;&lt;span style="color:silver;background:black"&gt;]&lt;br /&gt;    &lt;/span&gt;&lt;span style="color:#ff9428;background:black"&gt;public override object &lt;/span&gt;&lt;span style="color:#ffcb00;background:black"&gt;OnEntry&lt;/span&gt;&lt;span style="color:silver;background:black"&gt;(&lt;/span&gt;&lt;span style="color:#ff9428;background:black"&gt;object &lt;/span&gt;&lt;span style="color:#ffcb00;background:black"&gt;instance&lt;/span&gt;&lt;span style="color:silver;background:black"&gt;)&lt;br /&gt;    {&lt;br /&gt;      &lt;/span&gt;&lt;span style="color:green;background:black"&gt;// ...&lt;br /&gt;      &lt;/span&gt;&lt;span style="color:#ff9428;background:black"&gt;var &lt;/span&gt;&lt;span style="color:#ffcb00;background:black"&gt;sessionScope &lt;/span&gt;&lt;span style="color:silver;background:black"&gt;= &lt;/span&gt;&lt;span style="color:#ffcb00;background:black"&gt;sessionBound&lt;/span&gt;&lt;span style="color:silver;background:black"&gt;.&lt;/span&gt;&lt;span style="color:#ffcb00;background:black"&gt;ActivateContext&lt;/span&gt;&lt;span style="color:silver;background:black"&gt;();&lt;br /&gt;      &lt;/span&gt;&lt;span style="color:#ff9428;background:black"&gt;var &lt;/span&gt;&lt;span style="color:#ffcb00;background:black"&gt;transactionScope &lt;/span&gt;&lt;span style="color:silver;background:black"&gt;= &lt;/span&gt;&lt;span style="color:#ffcb00;background:black"&gt;Transaction&lt;/span&gt;&lt;span style="color:silver;background:black"&gt;.&lt;/span&gt;&lt;span style="color:#ffcb00;background:black"&gt;Open&lt;/span&gt;&lt;span style="color:silver;background:black"&gt;(&lt;/span&gt;&lt;span style="color:#ffcb00;background:black"&gt;sessionBound&lt;/span&gt;&lt;span style="color:silver;background:black"&gt;.&lt;/span&gt;&lt;span style="color:#ffcb00;background:black"&gt;Session&lt;/span&gt;&lt;span style="color:silver;background:black"&gt;, &lt;/span&gt;&lt;span style="color:#ff9428;background:black"&gt;true&lt;/span&gt;&lt;span style="color:silver;background:black"&gt;)&lt;br /&gt;      &lt;/span&gt;&lt;span style="color:#ff9428;background:black"&gt;return &lt;/span&gt;&lt;span style="color:#ffcb00;background:black"&gt;transactionScope&lt;/span&gt;&lt;span style="color:silver;background:black"&gt;.&lt;/span&gt;&lt;span style="color:#ffcb00;background:black"&gt;Join&lt;/span&gt;&lt;span style="color:silver;background:black"&gt;(&lt;/span&gt;&lt;span style="color:#ffcb00;background:black"&gt;sessionScope&lt;/span&gt;&lt;span style="color:silver;background:black"&gt;); &lt;/span&gt;&lt;span style="color:green;background:black"&gt;// Joins 2 disposables into one&lt;br /&gt;    &lt;/span&gt;&lt;span style="color:silver;background:black"&gt;}&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color:green;background:black"&gt;// ...&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color:gray;background:black"&gt;/// &amp;lt;inheritdoc/&amp;gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color:silver;background:black"&gt;[&lt;/span&gt;&lt;span style="color:#999655;background:black"&gt;DebuggerStepThrough&lt;/span&gt;&lt;span style="color:silver;background:black"&gt;]&lt;br /&gt;    &lt;/span&gt;&lt;span style="color:#ff9428;background:black"&gt;public override void &lt;/span&gt;&lt;span style="color:#ffcb00;background:black"&gt;OnExit&lt;/span&gt;&lt;span style="color:silver;background:black"&gt;(&lt;/span&gt;&lt;span style="color:#ff9428;background:black"&gt;object &lt;/span&gt;&lt;span style="color:#ffcb00;background:black"&gt;instance&lt;/span&gt;&lt;span style="color:silver;background:black"&gt;, &lt;/span&gt;&lt;span style="color:#ff9428;background:black"&gt;object &lt;/span&gt;&lt;span style="color:#ffcb00;background:black"&gt;onEntryResult&lt;/span&gt;&lt;span style="color:silver;background:black"&gt;)&lt;br /&gt;    {&lt;br /&gt;      &lt;/span&gt;&lt;span style="color:#ff9428;background:black"&gt;var &lt;/span&gt;&lt;span style="color:#ffcb00;background:black"&gt;d &lt;/span&gt;&lt;span style="color:silver;background:black"&gt;= (&lt;/span&gt;&lt;span style="color:#2b91af;background:black"&gt;IDisposable&lt;/span&gt;&lt;span style="color:silver;background:black"&gt;) &lt;/span&gt;&lt;span style="color:#ffcb00;background:black"&gt;onEntryResult&lt;/span&gt;&lt;span style="color:silver;background:black"&gt;;&lt;br /&gt;      &lt;/span&gt;&lt;span style="color:#ffcb00;background:black"&gt;d&lt;/span&gt;&lt;span style="color:silver;background:black"&gt;.&lt;/span&gt;&lt;span style="color:#ffcb00;background:black"&gt;DisposeSafely&lt;/span&gt;&lt;span style="color:silver;background:black"&gt;(); &lt;/span&gt;&lt;span style="color:green;background:black"&gt;// Safely disposes 2 disposables&lt;br /&gt;    &lt;/span&gt;&lt;span style="color:silver;background:black"&gt;}  &lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;P.S.&lt;/strong&gt; All the code provided here was taken from our &lt;a href="http://help.dataobjects.net/Default.aspx##DataObjects.Net_4-Essentials.chm/html/N_Xtensive_Core.htm"&gt;Xtensive.Core&lt;/a&gt; assembly. There are &lt;a href="http://help.dataobjects.net/Default.aspx##DataObjects.Net_4-Essentials.chm/html/T_Xtensive_Core_Disposing_JoiningDisposable.htm"&gt;JoiningDisposable&lt;/a&gt;, &lt;a href="http://help.dataobjects.net/Default.aspx##DataObjects.Net_4-Essentials.chm/html/T_Xtensive_Core_Disposing_DisposableExtensions.htm"&gt;DisposableExtensions&lt;/a&gt; and everything else I just described.&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Next time I'll tell you how to simplify safe dealing with &lt;strong&gt;IDisposable&lt;/strong&gt; further.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8486822413101972100-5747249071466843072?l=tips.x-tensive.com'/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=RZLd9Q43JZc:KNYYb7N0_no:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=RZLd9Q43JZc:KNYYb7N0_no:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?i=RZLd9Q43JZc:KNYYb7N0_no:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=RZLd9Q43JZc:KNYYb7N0_no:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=RZLd9Q43JZc:KNYYb7N0_no:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?i=RZLd9Q43JZc:KNYYb7N0_no:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://tips.x-tensive.com/feeds/5747249071466843072/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://tips.x-tensive.com/2009/08/making-idisposable-more-usable.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8486822413101972100/posts/default/5747249071466843072?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8486822413101972100/posts/default/5747249071466843072?v=2" /><link rel="alternate" type="text/html" href="http://tips.x-tensive.com/2009/08/making-idisposable-more-usable.html" title="Making IDisposable more usable, part 1" /><author><name>Alex Yakunin</name><uri>http://www.blogger.com/profile/13800929290476802273</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="09650213915253068470" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total></entry><entry gd:etag="W/&quot;AkQNRX85eCp7ImA9WxJbEEs.&quot;"><id>tag:blogger.com,1999:blog-8486822413101972100.post-9019426660212648770</id><published>2009-07-20T11:04:00.004+06:00</published><updated>2009-07-20T11:39:54.120+06:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-07-20T11:39:54.120+06:00</app:edited><title>Separate Microsoft Help 2.0 SDK installation</title><content type="html">It's well-known that Microsoft Help 2.0 SDK can be installed only as part of Visual Studio 2005/2008 SDK - there is simply no separate installer for it. Thanks to us, there is such an installer now, moreover, it contains both Microsoft Help 1.0 and Microsoft Help 2.0 SDKs.&lt;br /&gt;&lt;br /&gt;You can &lt;a href="http://www.x-tensive.com/Downloads/?Path=Freeware"&gt;download it here&lt;/a&gt; (as .rar archive) - there are just 2.8 MB instead of more than 100 MB you should normally install (Visual Studio 2008 SDK).&lt;br /&gt;&lt;br /&gt;Installation instructions:&lt;br /&gt;- Extract appropriate SDK folder(s) to "C:\Program Files\"&lt;br /&gt;- Use Install.bat and Uninstall.bat inside SDK folders to install or uninstall a particular one.&lt;br /&gt;- If you can't use "C:\Program Files\" as installation location, update paths in .reg files.&lt;br /&gt;&lt;br /&gt;Happy documenting ;)&lt;br /&gt;&lt;br /&gt;P.S. Check out &lt;a href="http://wiki.dataobjects.net/index.php?title=FiXml"&gt;FiXml&lt;/a&gt; - quite likely it will be helpful for you as well.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8486822413101972100-9019426660212648770?l=tips.x-tensive.com'/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=PJ7WtqKYYA0:XtNNgswJ8-U:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=PJ7WtqKYYA0:XtNNgswJ8-U:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?i=PJ7WtqKYYA0:XtNNgswJ8-U:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=PJ7WtqKYYA0:XtNNgswJ8-U:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=PJ7WtqKYYA0:XtNNgswJ8-U:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?i=PJ7WtqKYYA0:XtNNgswJ8-U:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://tips.x-tensive.com/feeds/9019426660212648770/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://tips.x-tensive.com/2009/07/separate-microsoft-help-20-sdk.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8486822413101972100/posts/default/9019426660212648770?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8486822413101972100/posts/default/9019426660212648770?v=2" /><link rel="alternate" type="text/html" href="http://tips.x-tensive.com/2009/07/separate-microsoft-help-20-sdk.html" title="Separate Microsoft Help 2.0 SDK installation" /><author><name>Alex Yakunin</name><uri>http://www.blogger.com/profile/13800929290476802273</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="09650213915253068470" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></entry><entry gd:etag="W/&quot;CEEESHs4fip7ImA9WxJRFUo.&quot;"><id>tag:blogger.com,1999:blog-8486822413101972100.post-4566311586192576602</id><published>2009-05-14T09:49:00.036+06:00</published><updated>2009-05-17T21:03:29.536+06:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-05-17T21:03:29.536+06:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="performance" /><category scheme="http://www.blogger.com/atom/ns#" term="extension methods" /><category scheme="http://www.blogger.com/atom/ns#" term="LINQ" /><category scheme="http://www.blogger.com/atom/ns#" term="expressions" /><title>Fast expression compilation</title><content type="html">Recently we've faced a well-known problem: &lt;a href="http://www.google.ru/search?q=LambdaExpression.Compile+is+slow"&gt;&lt;span style="font-weight: bold;"&gt;LambdaExpression.Compile&lt;/span&gt; is quite slow&lt;/a&gt;. Mainly, because of:&lt;br /&gt;- Huge amount of reflection&lt;br /&gt;- Excessive security checks&lt;br /&gt;- &lt;span style="font-style: italic;"&gt;Absence of any caching!&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;We've faced the issue while implementing compilation to executable providers for our &lt;a href="http://wiki.dataobjects.net/index.php?title=RSE"&gt;RecordSet engine&lt;/a&gt; for &lt;a href="http://wiki.dataobjects.net/"&gt;DO4&lt;/a&gt;. We should compile generally any expression, such as predicate passed to FilterProvider here. Event quite simple LINQ queries using just a single &lt;span style="font-weight: bold;"&gt;.Where&lt;/span&gt;  invocation normally require compilation of 2 expressions: one for original &lt;span style="font-weight: bold;"&gt;.Where&lt;/span&gt; criteria, and one - for index range definition for &lt;span style="font-weight: bold;"&gt;RangeSetProvider&lt;/span&gt; (we build it as expression).&lt;br /&gt;&lt;br /&gt;Obviously, we recommend everyone to use our cached queries in DO4 - they eliminate the problem. But what if you can't cache the query - e.g. if it is built dynamically, and actual instances almost always differ?&lt;br /&gt;&lt;br /&gt;So we've implemented &lt;span style="font-weight: bold;"&gt;LambdaExpression&lt;/span&gt; compilation cache. Being implemented well, it solves all the above problems.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;Raw results&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Simple expression compilation test:&lt;/span&gt;&lt;br /&gt;- Expression: &lt;span style="font-weight: bold;"&gt;(int a, int b) =&gt; a + b&lt;/span&gt;;&lt;br /&gt;- Without caching: &lt;span style="font-weight: bold;"&gt;15,884&lt;/span&gt; K compilations/s.&lt;br /&gt;- With caching: &lt;span style="font-weight: bold;"&gt;45,158&lt;/span&gt;&lt;span style="font-weight: bold;"&gt; &lt;/span&gt;K compilations/s.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Complex expression compilation test:&lt;/span&gt;&lt;br /&gt;- Expression: &lt;span style="font-weight: bold;"&gt;(int a, int b) =&gt; new {Result = a + b * 2 / a}.Result + DateTime.Now.Day * a * b - a + b&lt;/span&gt;&lt;br /&gt;- Without caching: &lt;span style="font-weight: bold;"&gt;0,&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;945&lt;/span&gt; K compilations/s.&lt;br /&gt;- With caching: &lt;span style="font-weight: bold;"&gt;25,747&lt;/span&gt; K compilations/s.&lt;br /&gt;&lt;br /&gt;As you see, &lt;span style="font-weight: bold;"&gt;the acceleration factor varies from ~ &lt;span style="color: rgb(204, 0, 0);"&gt;3x to 26x&lt;/span&gt;!&lt;/span&gt; Even this result seems very good. But we decided to investigate why results of standard .NET expression compilation differs so much here and implemented one more test:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Always new expression compilation test:&lt;/span&gt;&lt;br /&gt;- Expression: &lt;span style="font-weight: bold;"&gt;(int a, int b) =&gt; &lt;/span&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;i&lt;/span&gt;;&lt;br /&gt;- Without caching: &lt;span style="font-weight: bold;"&gt;1,707&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt; K compilations/s.&lt;br /&gt;- With caching: &lt;span style="font-weight: bold;"&gt;27,960&lt;/span&gt; K compilations/s.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;i&lt;/span&gt;&lt;/span&gt; is an integer increasing its value by one on each compilation attempt. &lt;span style="font-style: italic;"&gt;So it looks like there is already some kind of caching in .NET expression compilation logic.&lt;/span&gt; But IT FAILS even on such a simple case (difference in constant value)! Probably, they simply cache the compilation result using expression instance as key.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;So "true" acceleration factor is  at least &lt;span style="color: rgb(204, 0, 0);"&gt;16x&lt;/span&gt;.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;Implementation&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(204, 0, 0);"&gt;Note:&lt;/span&gt;&lt;span style="color: rgb(204, 0, 0);"&gt; Further I'll use &lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(204, 0, 0);"&gt;GenericType(of T)&lt;/span&gt;&lt;span style="color: rgb(204, 0, 0);"&gt; instead of standard C# notation with square brackets, because Blogger hates them - it simply cuts them out.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;There is &lt;span style="font-weight: bold;"&gt;Xtensive.Core.Linq.ExpressionCompileExtensions&lt;/span&gt; class providing a set of additional &lt;span style="font-weight: bold;"&gt;.CachingCompile()&lt;/span&gt; methods to &lt;span style="font-weight: bold;"&gt;Expression&lt;/span&gt; type. Its usage is almost the same as of original &lt;span style="font-weight: bold;"&gt;.Compile&lt;/span&gt; method:&lt;br /&gt;- Original code: &lt;span style="font-weight: bold;"&gt;var compiledLambda = lambda.Compile()&lt;/span&gt;;&lt;br /&gt;- New code: &lt;span style="font-weight: bold;"&gt;var compiledLambda  = lambda.&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Caching&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Compile()&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;How it &lt;span style="font-style: italic;"&gt;could&lt;/span&gt; work:&lt;br /&gt;- Find cached version of provided expression tree in some dictionary&lt;br /&gt;- Return its compiled version, if it exists; otherwise, compile &amp;amp; cache it.&lt;br /&gt;&lt;br /&gt;Actually everything is much more complex:&lt;br /&gt;- Expressions aren't comparable for equality. They neither override &lt;span style="font-weight: bold;"&gt;Equals&lt;/span&gt;, nor &lt;span style="font-weight: bold;"&gt;GetHashCode&lt;/span&gt;. But comparison for equalitry is required to use them as key in dictionary. We can't use default implmentation as well - &lt;span style="font-weight: bold;"&gt;Expression&lt;/span&gt; instances are almost always built anew rather than cached.&lt;br /&gt;- Even if they would be comparable for equality, they won't really be equal because of closures: a new instance of closure is referenced by corresponding &lt;span style="font-weight: bold;"&gt;ConstantExpression&lt;/span&gt; on the subsequent creation of expression tree. Even if we could be able to compare such constants for equality, they would almost always differ.&lt;br /&gt;&lt;br /&gt;So we've implemented:&lt;br /&gt;- &lt;span style="font-weight: bold;"&gt;ExpressionTree&lt;/span&gt; class implementing &lt;span style="font-weight: bold;"&gt;IEquatable(of ExpressionTree)&lt;/span&gt;, and properly overriding default &lt;span style="font-weight: bold;"&gt;GetHashCode&lt;/span&gt; &amp;amp; &lt;span style="font-weight: bold;"&gt;Equals&lt;/span&gt;. This allows us to compare expressions.&lt;br /&gt;- &lt;span style="font-weight: bold;"&gt;ConstantExtractor&lt;/span&gt; - a visitor rewriting the original expression and removing any dependencies on constants from it. In fact, we rewrite original expression replacing each &lt;span style="font-weight: bold;"&gt;const&lt;/span&gt; of type &lt;span style="font-weight: bold;"&gt;T&lt;/span&gt; there to &lt;span style="font-weight: bold;"&gt;((T) additionalLambdaParameter[constNumber])&lt;/span&gt; there. E.g. &lt;span style="font-weight: bold;"&gt;() =&gt; 1&lt;/span&gt; would be rewritten to &lt;span style="font-weight: bold;"&gt;(consts) =&gt; ((int) consts&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;[0])&lt;/span&gt;, and we would cache this expression. &lt;span style="font-weight: bold;"&gt;ConstantExtractor&lt;/span&gt; builds the array of constant values (actual &lt;span style="font-weight: bold;"&gt;consts&lt;/span&gt; value) during processing of the original expression. Since this happens on any attempt to compile the expression by our caching compiler (because first of all we must build caching key - an &lt;span style="font-weight: bold;"&gt;ExpressionTree&lt;/span&gt; containing no constants), we always have this array of constants.&lt;br /&gt;- So in the end we always have both compiled expression (processed by &lt;span style="font-weight: bold;"&gt;ConstantExtractor&lt;/span&gt;) and the array of constants. So we should just "bind" this array to the comiled expression. "Bind" means converting a pair of &lt;span style="font-weight: bold;"&gt;f(consts,a,b,c, ...)&lt;/span&gt; and &lt;span style="font-weight: bold;"&gt;extractedConsts&lt;/span&gt; to &lt;span style="font-weight: bold;"&gt;g(a,b,c, ...) = f(&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;extractedConsts&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;,a,b,c, ...)&lt;/span&gt;. This actually done by corresponding overload of &lt;span style="font-weight: bold;"&gt;.&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Caching&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Compile&lt;/span&gt; method. Its typical code is:&lt;br /&gt;&lt;pre&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;public static Func(of T1, T2, ..., TResult) &lt;/span&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;Caching&lt;/span&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;Compile(of T1, T2, ..., TResult)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;  (this Expression(of Func(of T1, T2, TResult)) lambda)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;  var result = CachingExpressionCompiler.Instance.Compile(lambda);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;  return ((Func(of object[], T1, T2, ...)) result.First).Bind(result.Second);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 153);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;span style="font-weight: bold;"&gt;.Bind&lt;/span&gt; is one more extension method provided by &lt;span style="font-weight: bold;"&gt;Xtensive.Core.Helpers.DelegateBindExtensions&lt;/span&gt; class.&lt;br /&gt;All &lt;span style="font-weight: bold;"&gt;.Bind&lt;/span&gt; and &lt;span style="font-weight: bold;"&gt;.&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Caching&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Compile&lt;/span&gt; versions are generated by &lt;a href="http://tips.x-tensive.com/2009/05/built-in-visual-studio-2008-code.html"&gt;T4 templates&lt;/a&gt; - finally we've found the place where we could use them ;)&lt;br /&gt;&lt;br /&gt;And finally, we use our &lt;span style="font-weight: bold;"&gt;ThreadSafeDictionary&lt;/span&gt; as actual cache, so any cached compiled result is &lt;span style="font-style: italic;"&gt;never purged&lt;/span&gt;. Initially this may look as a serious lack, but actually it isn't: currently .NET is incapable of unloading &lt;span style="font-style: italic;"&gt;any&lt;/span&gt; IL code. Even if we don't use cache, expression compilation eats some RAM, and this RAM is never released. So our "caching compiler" just eats a bit more - certainly, only if we don't hit the cache.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;Conclusions&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Pros and cons:&lt;/span&gt;&lt;br /&gt;- We've got much faster expression compilation&lt;br /&gt;- It's quite likely this solution significantly decreases the amount of RAM consumed by complied expressions during the application lifetime, since it significantly decrease the number of actual compilations.&lt;br /&gt;- The compiled expression we return is a bit slower, because we replace constants to array accessors there and add one more delegate call (&lt;span style="font-weight: bold;"&gt;.Bind&lt;/span&gt; method does this). But I feel this will be acceptable in 99.9% of cases.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Possible improvements:&lt;/span&gt;&lt;br /&gt;- Use lightweight expression adapters instead of &lt;span style="font-weight: bold;"&gt;Expression&lt;/span&gt; descendants as result of &lt;span style="font-weight: bold;"&gt;ConstantExtractor&lt;/span&gt;&lt;span&gt;, such as the ones from &lt;/span&gt;&lt;a href="http://www.codeplex.com/metalinq"&gt;MetaLinq&lt;/a&gt;. .NET expressions perform lots of checks during their construction, which aren't necessary here. We must just be able to compare such tree for equality with another one, compute its hash code, and much rarely - convert it to .NET expressions to get it compiled. I feel this should improve the performance at least twice.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;Usage&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;- &lt;a href="http://www.x-tensive.com/Downloads/?Path=DataObjects.Net_4"&gt;Download DO4&lt;/a&gt; - it contains compiled version of &lt;span style="font-weight: bold;"&gt;Xtensive.Core.dll&lt;/span&gt;, as well as its source code&lt;br /&gt;- Add reference to &lt;span style="font-weight: bold;"&gt;Xtensive.Core.dll&lt;/span&gt; to your project&lt;br /&gt;- Add "&lt;span style="font-weight: bold;"&gt;using Xtensive.Core.Linq;&lt;/span&gt;" to C# file containing &lt;span style="font-weight: bold;"&gt;lambda.Compile()&lt;/span&gt;&lt;br /&gt;- Replace &lt;span style="font-weight: bold;"&gt;lambda.Compile()&lt;/span&gt;&lt;span&gt; to &lt;/span&gt;&lt;span style="font-weight: bold;"&gt;lambda.&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Caching&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Compile()&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8486822413101972100-4566311586192576602?l=tips.x-tensive.com'/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=EnJSRuKgAG8:mBdoGzGVR34:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=EnJSRuKgAG8:mBdoGzGVR34:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?i=EnJSRuKgAG8:mBdoGzGVR34:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=EnJSRuKgAG8:mBdoGzGVR34:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=EnJSRuKgAG8:mBdoGzGVR34:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?i=EnJSRuKgAG8:mBdoGzGVR34:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://tips.x-tensive.com/feeds/4566311586192576602/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://tips.x-tensive.com/2009/05/fast-expression-compilation.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8486822413101972100/posts/default/4566311586192576602?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8486822413101972100/posts/default/4566311586192576602?v=2" /><link rel="alternate" type="text/html" href="http://tips.x-tensive.com/2009/05/fast-expression-compilation.html" title="Fast expression compilation" /><author><name>Alex Yakunin</name><uri>http://www.blogger.com/profile/13800929290476802273</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="09650213915253068470" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total></entry><entry gd:etag="W/&quot;Dk8GSHo9fyp7ImA9WxJREUQ.&quot;"><id>tag:blogger.com,1999:blog-8486822413101972100.post-1760502279511643695</id><published>2009-05-06T00:53:00.011+06:00</published><updated>2009-05-13T12:07:09.467+06:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-05-13T12:07:09.467+06:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="visual studio" /><category scheme="http://www.blogger.com/atom/ns#" term="unknown features" /><title>Built-in Visual Studio 2008 Code Generator</title><content type="html">Have you ever heard about code generator built-in VS 2008 by default? Microsoft named it &lt;b&gt;"T4:&amp;nbsp;Text&amp;nbsp;Template&amp;nbsp;Transformation&amp;nbsp;Toolkit"&lt;/b&gt;. It is integrated into Visual Studio and very easy to use. Let me demonstrate it on example.&lt;br /&gt;&lt;br /&gt;Let us suppose we need a class with methods like those for such primitive types as Int32, Double, Decimal, DateTime, TimeSpan and other.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;public static Double ParseDouble(string value)&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (value == "Default")&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return default(Double);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (value == "MinValue")&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return Double.MinValue;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (value == "MaxValue")&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return Double.MaxValue;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return Double.Parse(value);&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;public static Double? ParseNullableDouble(string value)&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (value == "Default")&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return default(Double);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (value == "MinValue")&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return Double.MinValue;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (value == "MaxValue")&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return Double.MaxValue;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (value == "Null")&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return null;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return Double.Parse(value);&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Because it isn't very interesting to implement it manually I suggest to use built-in code generator. How we can do this:&lt;br /&gt;&lt;br /&gt;1. Create class SmartParser.cs and implement those methods for one type, e.g. for Int32&lt;br /&gt;2. Rename SmartParser.cs to SmartParser.tt&lt;br /&gt;3. Now it is possible to use ASP.NET-like tags &lt;b&gt;&lt;# #&gt;&lt;/b&gt; and &lt;b&gt;&lt;#= #&gt;&lt;/b&gt; to generate this code for all types we need and Visual Studio will automatically create file SmartParser.cs&lt;br /&gt;&lt;br /&gt;In our case SmartParser.tt will look like this:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;using System;&lt;br /&gt;&lt;br /&gt;public static class SmartParser&lt;br /&gt;{&lt;br /&gt;&lt;b&gt;&lt;#&lt;br /&gt;Type[] types = new Type[] {&lt;br /&gt;&amp;nbsp;&amp;nbsp;typeof(Int32),&lt;br /&gt;&amp;nbsp;&amp;nbsp;typeof(Double),&lt;br /&gt;&amp;nbsp;&amp;nbsp;typeof(Decimal),&lt;br /&gt;&amp;nbsp;&amp;nbsp;typeof(DateTime),&lt;br /&gt;&amp;nbsp;&amp;nbsp;typeof(TimeSpan)&lt;br /&gt;};&lt;br /&gt;foreach (Type type in types) {&lt;br /&gt;#&gt;&lt;/b&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;public static &lt;b&gt;&lt;#=type.Name#&gt;&lt;/b&gt; Parse&lt;b&gt;&lt;#=type.Name#&gt;&lt;/b&gt;(string value)&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (value == "Default")&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return default(&lt;b&gt;&lt;#=type.Name#&gt;&lt;/b&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (value == "MinValue")&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return &lt;b&gt;&lt;#=type.Name#&gt;&lt;/b&gt;.MinValue;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (value == "MaxValue")&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return &lt;b&gt;&lt;#=type.Name#&gt;&lt;/b&gt;.MaxValue;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return &lt;b&gt;&lt;#=type.Name#&gt;&lt;/b&gt;.Parse(value);&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;public static &lt;b&gt;&lt;#=type.Name#&gt;&lt;/b&gt;? ParseNullable&lt;b&gt;&lt;#=type.Name#&gt;&lt;/b&gt;(string value)&lt;br /&gt;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (value == "Default")&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return default(&lt;b&gt;&lt;#=type.Name#&gt;&lt;/b&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (value == "MinValue")&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return &lt;b&gt;&lt;#=type.Name#&gt;&lt;/b&gt;.MinValue;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (value == "MaxValue")&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return &lt;b&gt;&lt;#=type.Name#&gt;&lt;/b&gt;.MaxValue;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (value == "Null")&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return null;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return &lt;b&gt;&lt;#=type.Name#&gt;&lt;/b&gt;.Parse(value);&lt;br /&gt;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&lt;b&gt;&lt;# &lt;br /&gt;} &lt;br /&gt;#&gt;&lt;/b&gt;&lt;br /&gt;}&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Now we can open automatically generated SmartParser.cs just to ensure, that everything is OK and our "huge" class is successfully generated (-;&lt;br /&gt;&lt;br /&gt;You can generate not only *.cs files, but *.xml, *.txt, *.html and generally text files with any extension. There are also several useful directives, for example:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;b&gt;&lt;#@ output extension="txt" #&gt;&lt;br /&gt;&lt;#@ template language="C#v3.5" #&gt;&lt;br /&gt;&lt;#@ import namespace="System.Linq" #&gt;&lt;br /&gt;&lt;#@ assembly name="System.Core" #&gt;&lt;/b&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Any additional information on T4 can be easily found оn the web.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8486822413101972100-1760502279511643695?l=tips.x-tensive.com'/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=OpVhi2vhwnc:9l48PZ3LeWk:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=OpVhi2vhwnc:9l48PZ3LeWk:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?i=OpVhi2vhwnc:9l48PZ3LeWk:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=OpVhi2vhwnc:9l48PZ3LeWk:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=OpVhi2vhwnc:9l48PZ3LeWk:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?i=OpVhi2vhwnc:9l48PZ3LeWk:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://tips.x-tensive.com/feeds/1760502279511643695/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://tips.x-tensive.com/2009/05/built-in-visual-studio-2008-code.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8486822413101972100/posts/default/1760502279511643695?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8486822413101972100/posts/default/1760502279511643695?v=2" /><link rel="alternate" type="text/html" href="http://tips.x-tensive.com/2009/05/built-in-visual-studio-2008-code.html" title="Built-in Visual Studio 2008 Code Generator" /><author><name>Alex Kofman</name><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="08236257915143259754" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total></entry><entry gd:etag="W/&quot;Dk8ERX4zfip7ImA9WxRVEkk.&quot;"><id>tag:blogger.com,1999:blog-8486822413101972100.post-5640811270898429750</id><published>2008-11-09T00:16:00.013+05:00</published><updated>2008-11-09T20:33:24.086+05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-11-09T20:33:24.086+05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="unit testing" /><category scheme="http://www.blogger.com/atom/ns#" term="internal" /><category scheme="http://www.blogger.com/atom/ns#" term="attributes" /><title>Are internal members really internal?</title><content type="html">&lt;div&gt;Each C# developer knows the "internal" access level keyword — The "internal" keyword is an access modifier for types and type members. Internal types or members are accessible only within the same assembly. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;But don't be fully confident in it when dealing with microsofties. Those artful guys invented in the .Net Framework 2.0 a special attribute — "&lt;a href="http://msdn2.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute.aspx"&gt;InternalsVisibleToAttribute&lt;/a&gt;"  and now your internal members can become - guess what? - public! (of course they will be visible only for specified assemblies).&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;No one knows the real reason for such an "invention" but this innovation has been highly estimated by test-driven development adopters because the usage of this attribute allows your test libraries to access internal classes and methods for additional testing and coverage.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I think that any other usage of it can be considered a lack of architectural design but what about the microsofties? Do they use it for product-level assemblies or for testing purposes only? Let's see. Oren Eini made some interesting &lt;a href="http://ayende.com/Blog/archive/2008/06/27/On-InternalsVisibleTo.aspx"&gt;investigation&lt;/a&gt;  on how the attribute is used inside the .Net Framework:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;System.Data allows:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;System.Data.Entity&lt;br /&gt;&lt;/li&gt;&lt;li&gt;SqlAccess&lt;br /&gt;&lt;/li&gt;&lt;li&gt;System.Data.DataSetExtensions&lt;/li&gt;&lt;/ul&gt;Microsoft.NETCF.Tools allows:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;System.Web.Services&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;Microsoft.Office.Tools.Common.v9.0 allows:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Microsoft.Office.Tools.Word.v9.0&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Microsoft.VisualStudio.Tools.Office.Designer.Office2007&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Microsoft.VisualStudio.Tools.Office.Designer.Office2007Tests&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Microsoft.VisualStudio.Tools.Office.Outlook.UnitTests&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;Microsoft.Build.Conversion allows:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Microsoft.Build.Conversion.Unittest&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;Microsoft.Build.Engine allows:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Microsoft.Build.Engine.Unittest&lt;/li&gt;&lt;/ul&gt;System.Core allows:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Dlinq.Unittests&lt;/li&gt;&lt;/ul&gt;And so on.&lt;div&gt;&lt;br /&gt;As for Xtensive products, unit testing is the only application of the "InternalsVisibleTo" attribute.&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8486822413101972100-5640811270898429750?l=tips.x-tensive.com'/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=uKN02GBrJzg:g8g7E2uT7ak:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=uKN02GBrJzg:g8g7E2uT7ak:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?i=uKN02GBrJzg:g8g7E2uT7ak:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=uKN02GBrJzg:g8g7E2uT7ak:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=uKN02GBrJzg:g8g7E2uT7ak:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?i=uKN02GBrJzg:g8g7E2uT7ak:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://tips.x-tensive.com/feeds/5640811270898429750/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://tips.x-tensive.com/2008/11/are-internal-members-really-internal.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8486822413101972100/posts/default/5640811270898429750?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8486822413101972100/posts/default/5640811270898429750?v=2" /><link rel="alternate" type="text/html" href="http://tips.x-tensive.com/2008/11/are-internal-members-really-internal.html" title="Are internal members really internal?" /><author><name>Dmitri Maximov</name><uri>http://www.blogger.com/profile/07143844311415529548</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="04085565420510170333" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></entry><entry gd:etag="W/&quot;CUEERX48eSp7ImA9WxRVEEk.&quot;"><id>tag:blogger.com,1999:blog-8486822413101972100.post-379895387411995695</id><published>2008-11-07T11:26:00.006+05:00</published><updated>2008-11-07T12:40:04.071+05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-11-07T12:40:04.071+05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="garbage collection" /><category scheme="http://www.blogger.com/atom/ns#" term="memory leaks" /><category scheme="http://www.blogger.com/atom/ns#" term="finalization" /><title>Link: object disposal, finalization and resource management</title><content type="html">This time I publish a &lt;a href="http://www.bluebytesoftware.com/blog/2005/04/08/DGUpdateDisposeFinalizationAndResourceManagement.aspx"&gt;link to an article&lt;/a&gt; - the article itself is really perfect. "Must know" for any .NET developer.&lt;br /&gt;&lt;br /&gt;Here are some quotations from it to make you a bit more interested:&lt;br /&gt;- Do allow your Dispose method to be called &lt;span style="font-style: italic;"&gt;more than once&lt;/span&gt;. The method may choose to do nothing after the first call. It should not generate an exception.&lt;br /&gt;- Consider setting disposed fields to null &lt;span style="font-style: italic;"&gt;before&lt;/span&gt; actually executing Dispose when reference cycles in an object graph are possible.&lt;br /&gt;- &lt;span style="font-style: italic;"&gt;Avoid throwing an exception from within Dispose&lt;/span&gt; except under critical situations where the containing process has been corrupted.&lt;br /&gt;- &lt;span style="font-style: italic;"&gt;Do not&lt;/span&gt;&lt;span style="font-style: italic;"&gt; assume your finalizer will always run.&lt;/span&gt;&lt;br /&gt;- &lt;span style="font-style: italic;"&gt; Do &lt;/span&gt;&lt;span style="font-style: italic;"&gt;write finalizers that are tolerant of partially constructed instances&lt;/span&gt;&lt;span style="font-style: italic;"&gt;.&lt;/span&gt;&lt;br /&gt;- &lt;span style="font-style: italic;"&gt;Do write finalizers that are threading-agnostic.&lt;/span&gt; Finalizers can execute in any order, on any thread, can occur on multiple objects concurrently, and even on the same object simultaneously.&lt;br /&gt;- Do gracefully handle situations &lt;span style="font-style: italic;"&gt;in which your finalizer is invoked more than onc&lt;/span&gt;e.&lt;br /&gt;&lt;br /&gt;The original article is &lt;a href="http://www.bluebytesoftware.com/blog/2005/04/08/DGUpdateDisposeFinalizationAndResourceManagement.aspx"&gt;here&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8486822413101972100-379895387411995695?l=tips.x-tensive.com'/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=QEOplcORCF4:_xu5-yhNGrM:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=QEOplcORCF4:_xu5-yhNGrM:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?i=QEOplcORCF4:_xu5-yhNGrM:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=QEOplcORCF4:_xu5-yhNGrM:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=QEOplcORCF4:_xu5-yhNGrM:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?i=QEOplcORCF4:_xu5-yhNGrM:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://tips.x-tensive.com/feeds/379895387411995695/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://tips.x-tensive.com/2008/11/excellent-article-about-object-disposal.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8486822413101972100/posts/default/379895387411995695?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8486822413101972100/posts/default/379895387411995695?v=2" /><link rel="alternate" type="text/html" href="http://tips.x-tensive.com/2008/11/excellent-article-about-object-disposal.html" title="Link: object disposal, finalization and resource management" /><author><name>Alex Yakunin</name><uri>http://www.blogger.com/profile/13800929290476802273</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="09650213915253068470" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></entry><entry gd:etag="W/&quot;Ak8AQ3Y7cCp7ImA9WxRWFE8.&quot;"><id>tag:blogger.com,1999:blog-8486822413101972100.post-8720656645137913720</id><published>2008-10-30T11:36:00.009+05:00</published><updated>2008-10-31T09:54:02.808+05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-10-31T09:54:02.808+05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="performance" /><category scheme="http://www.blogger.com/atom/ns#" term="thread safety" /><category scheme="http://www.blogger.com/atom/ns#" term="unknown features" /><title>The cost of [ThreadStatic] attribute</title><content type="html">First of all, raw results:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;Instance field: Operations: 2,650 B/s.&lt;br /&gt;Static field: Operations: 2,630 B/s.&lt;br /&gt;Volatile instance field: Operations: 2,649 B/s.&lt;br /&gt;[ThreadStatic] field: Operations: 43,611 M/s.&lt;br /&gt;Thread data slot: Operations: 4,068 M/s.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;The test is actually quite simple: we read specified field in a loop. As before, on Core 2 Duo @2.66GHz. The code can be found in &lt;a href="http://www.x-tensive.com/Downloads/?Path=DataObjects.Net_4" rel="nofollow"&gt;DataObjects.Net 4.0&lt;/a&gt; test suite, see &lt;span style="font-style: italic;"&gt;Xtensive.Core\Xtensive.Core.Tests\DotNetFramework\FieldTypeTest.cs.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Conclusions:&lt;br /&gt;- &lt;span style="font-weight: bold;"&gt;Reading regular, static or volatile field is quite cheap: ~ 0.2x&lt;/span&gt; in &lt;a href="http://tips.x-tensive.com/2008/10/method-call-performance.html"&gt;previously introduced metrics&lt;/a&gt;, or 20% of virtual method call time&lt;br /&gt;- &lt;span style="font-weight: bold;"&gt;[ThreadStatic] fields are actually quite costly in comparison to others: ~ 14x&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;Now the main question: &lt;span style="font-style: italic;"&gt;why&lt;/span&gt;? It isn't so obvious [ThreadStatic] is ~ 60 times slower than static.&lt;br /&gt;&lt;br /&gt;JITted [ThreadStatic] access code actually always consists of two parts:&lt;br /&gt;- Call to a system routine returning address of [ThreadStatic] field by its token&lt;br /&gt;- Regular field access instruction.&lt;br /&gt;&lt;br /&gt;Obviously, the first part (call) "eats" almost the whole execution time: there is no more efficient way to get the address of such a field by its token rather than using hash table. As I've mentioned &lt;a href="http://tips.x-tensive.com/2008/10/method-call-performance.html"&gt;before&lt;/a&gt;, &lt;span style="font-style: italic;"&gt;reading from a system hash table takes ~ 10x&lt;/span&gt;. So that's nearly what we have in this case.&lt;br /&gt;&lt;br /&gt;Why they're implemented this way in .NET? I can't imagine why they didn't use some faster approach. E.g. I suspect calculating the lowest stack boundary (as well as the upper one) from the current stack pointer value is quite simple operation - something like &lt;span style="font-style: italic;"&gt;bitwise and&lt;/span&gt;. Why we can't store the address of the first [ThreadStatic] location as fixed address nearby it, and use constant offset for each [ThreadStatic] field relatively to the address of the first one? In this case it would take ~ &lt;span style="font-weight: bold;"&gt;1x&lt;/span&gt; to access it...&lt;br /&gt;&lt;br /&gt;Ok, this is what could be, but in reality we have &lt;span style="font-weight: bold;"&gt;14x&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;Finally, there are thread data slots as well. But they're 10 times slower than [ThreadStatic] fields, so it's always better to simulate their behavior with e.g. a Dictionary stored in [ThreadStatic] field.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8486822413101972100-8720656645137913720?l=tips.x-tensive.com'/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=Dc4bdzPNYVc:RO06MZ3lpOg:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=Dc4bdzPNYVc:RO06MZ3lpOg:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?i=Dc4bdzPNYVc:RO06MZ3lpOg:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=Dc4bdzPNYVc:RO06MZ3lpOg:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=Dc4bdzPNYVc:RO06MZ3lpOg:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?i=Dc4bdzPNYVc:RO06MZ3lpOg:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://tips.x-tensive.com/feeds/8720656645137913720/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://tips.x-tensive.com/2008/10/cost-of-threadstatic-attribute.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8486822413101972100/posts/default/8720656645137913720?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8486822413101972100/posts/default/8720656645137913720?v=2" /><link rel="alternate" type="text/html" href="http://tips.x-tensive.com/2008/10/cost-of-threadstatic-attribute.html" title="The cost of [ThreadStatic] attribute" /><author><name>Alex Yakunin</name><uri>http://www.blogger.com/profile/13800929290476802273</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="09650213915253068470" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></entry><entry gd:etag="W/&quot;DUcGRXo9fCp7ImA9WxRWFE8.&quot;"><id>tag:blogger.com,1999:blog-8486822413101972100.post-759734529913868582</id><published>2008-10-29T10:26:00.013+05:00</published><updated>2008-10-31T09:23:44.464+05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-10-31T09:23:44.464+05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="performance" /><category scheme="http://www.blogger.com/atom/ns#" term="generics" /><title>The cost of method calls</title><content type="html">Here I'll talk about the cost (or performance) of various ways of method invocation in .NET.&lt;br /&gt;&lt;br /&gt;First of all, let's assume:&lt;br /&gt;- &lt;span style="font-weight: bold;"&gt;Virtual method call time is 1x.&lt;/span&gt; This is about ~ 600M calls / sec. on Core 2 Duo @ 2.66 GHz. To be precise, we're talking about instance method getting no arguments and returning a single Int32 value (i.e. it is an average property getter).&lt;br /&gt;&lt;br /&gt;So:&lt;br /&gt;- &lt;span style="font-weight: bold;"&gt;Delegate method call time is 1.5x&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt; (the same method invoked by delegate pointing to it)&lt;br /&gt;- &lt;span style="font-weight: bold;"&gt;Interface method call time is &lt;/span&gt;&lt;span style="font-weight: bold;"&gt;2&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;x&lt;/span&gt; (the same method invoked on reference of interface type)&lt;br /&gt;&lt;br /&gt;A bit surprising, yes? The explanation is &lt;a href="http://www.codeproject.com/KB/cs/net_type_internals.aspx"&gt;here&lt;/a&gt;. Briefly, interface method dispatch is more complex than delegate dispatch, since we must locate appropriate interface method table for the instance we have first. If count of implemented interfaces on a particular type is quite large (that's actually almost impossible), the only good way to do this is to use hash table. But if it is small (that's the most frequent case), there must be just a search in small [possibly - ordered] list. But this is anyway more complex than in case with delegate, since delegate already contains the exact method address (this isn't correct for &lt;a href="http://tips.x-tensive.com/2008/10/open-delegates_8670.html"&gt;open delegates&lt;/a&gt;).&lt;br /&gt;&lt;br /&gt;Now one more fact to think about: all the tests I'm talking about are &lt;span style="font-style: italic;"&gt;loop-based&lt;/span&gt;, performed in Release configuration, and their code is nearly the following:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;for (int i = 0; i&amp;lt;...; i+=10) {&lt;br /&gt;o = c.GetValue();&lt;br /&gt;o = c.GetValue();&lt;br /&gt;o = c.GetValue();&lt;br /&gt;o = c.GetValue();&lt;br /&gt;o = c.GetValue();&lt;br /&gt;o = c.GetValue();&lt;br /&gt;o = c.GetValue();&lt;br /&gt;o = c.GetValue();&lt;br /&gt;o = c.GetValue();&lt;br /&gt;o = c.GetValue();&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;.NET is able to cache resolved interface method tables (and possibly - even method addresses), so calling interface method in a loop must be a bit faster, than calling it once. So in general the cost of interface method call in comparison to delegate call is even bigger.&lt;br /&gt;&lt;br /&gt;This explains why we have such types as &lt;a href="http://help.x-tensive.com/Default.aspx##DataObjects.Net%20v4.0/html/T_Xtensive_Core_Hashing_Hasher_1.htm"&gt;Hasher(of T)&lt;/a&gt; (Comparer, Arithmetic, etc.). They cache the delegates performing a set of operations on T type faster than with use of similar interface in their fields. See e.g. &lt;a href="http://help.x-tensive.com/Default.aspx##DataObjects.Net%20v4.0/html/F_Xtensive_Core_Hashing_Hasher_1_GetHash.htm"&gt;Hasher(of T).GetHash field&lt;/a&gt;. Certainly, such an approach is used only when &lt;span style="font-style: italic;"&gt;performance is essential&lt;/span&gt; - i.e. when it's well known these operations will be invoked many times e.g. on any &lt;a href="http://wiki.dataobjects.net/index.php?title=Index_seek"&gt;index seek&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Let's look of few more metrics:&lt;br /&gt;- &lt;span style="font-weight: bold;"&gt;Creating a delegate pointing to non-virtual method time is 7.5&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;x&lt;/span&gt;&lt;br /&gt;- &lt;span style="font-weight: bold;"&gt;Creating a delegate pointing to virtual method time is 50x&lt;/span&gt;&lt;br /&gt;- &lt;span style="font-weight: bold;"&gt;Creating a delegate pointing to interface method time is 150&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;x&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;So &lt;span style="font-style: italic;"&gt;delegate construction isn't cheap at all&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;Now we're turning to virtual generic methods:&lt;br /&gt;- &lt;span style="font-weight: bold;"&gt;Virtual generic method call time is 10x&lt;/span&gt; - independently on of it is called on interface or not. Dependency on count of generic arguments almost absents as well - adding one more argument makes the call longer by ~ 0.5%.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;- Creating a delegate pointing to generic virtual method time is 1000x&lt;/span&gt;. Not sure, why - it looks like because of some bug in .NET. Since delegates in .NET may point to fully parameterized methods only (they store method address), so &lt;span style="font-weight: bold;"&gt;the time of calling such a delegate is 1.5x, as before&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;Why it's so costly to call virtual generic method? Because there can be generally any number of its implementations, dependently on the argument substitution, so .NET framework resolves its address using internal hash table, that must be bound to corresponding virtual (or interface) method table.&lt;br /&gt;&lt;br /&gt;So we may also take that:&lt;br /&gt;- &lt;span style="font-weight: bold;"&gt;Internal hash table seek time is ~ 10x&lt;/span&gt; - I'll use this time in my future posts to show how to estimate the cost of generally any basic operation in .NET.&lt;br /&gt;&lt;br /&gt;And few conclusions related to generic virtual methods:&lt;br /&gt;- &lt;span style="font-weight: bold;"&gt;The smallest heap allocation time is 3.5x; Int32 boxing time is 4x (with its heap allocation).&lt;/span&gt; So it's almost always cheaper to have non-generic virtual method with &lt;span style="font-style: italic;"&gt;object&lt;/span&gt; type argument, rather than generic virtual method.&lt;br /&gt;- If generic virtual method seems anyway preferable, you might &lt;span style="font-style: italic;"&gt;think about implementing its "call caching" with use of delegates&lt;/span&gt;. E.g. we use &lt;a href="http://help.x-tensive.com/Default.aspx##DataObjects.Net%20v4.0/html/M_Xtensive_Core_Reflection_DelegateHelper_CreateDelegates__1.htm"&gt;DelegateHelper.CreateDelegates&lt;/a&gt; and &lt;a href="http://help.x-tensive.com/Default.aspx##DataObjects.Net%20v4.0/html/M_Xtensive_Core_Reflection_DelegateHelper_ExecuteDelegates__1.htm"&gt;DelegateHelper.ExecuteDelegates&lt;/a&gt; methods to perform the operations on &lt;a href="http://help.x-tensive.com/Default.aspx##DataObjects.Net%20v4.0/html/T_Xtensive_Core_Tuples_Tuple.htm"&gt;Tuples&lt;/a&gt; of the same structure faster.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8486822413101972100-759734529913868582?l=tips.x-tensive.com'/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=kCpVJ71B4ck:AfrWF4JfVFc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=kCpVJ71B4ck:AfrWF4JfVFc:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?i=kCpVJ71B4ck:AfrWF4JfVFc:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=kCpVJ71B4ck:AfrWF4JfVFc:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=kCpVJ71B4ck:AfrWF4JfVFc:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?i=kCpVJ71B4ck:AfrWF4JfVFc:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://tips.x-tensive.com/feeds/759734529913868582/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://tips.x-tensive.com/2008/10/method-call-performance.html#comment-form" title="6 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8486822413101972100/posts/default/759734529913868582?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8486822413101972100/posts/default/759734529913868582?v=2" /><link rel="alternate" type="text/html" href="http://tips.x-tensive.com/2008/10/method-call-performance.html" title="The cost of method calls" /><author><name>Alex Yakunin</name><uri>http://www.blogger.com/profile/13800929290476802273</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="09650213915253068470" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">6</thr:total></entry><entry gd:etag="W/&quot;DEADSXo5eSp7ImA9WxRWFE8.&quot;"><id>tag:blogger.com,1999:blog-8486822413101972100.post-1519653532449129643</id><published>2008-10-26T01:19:00.014+06:00</published><updated>2008-10-31T09:19:38.421+05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-10-31T09:19:38.421+05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="performance" /><category scheme="http://www.blogger.com/atom/ns#" term="unknown features" /><title>Open delegates</title><content type="html">Do you know what is &lt;span style="font-style: italic;"&gt;open delegate&lt;/span&gt;? I was quite surprised when I knew this. They exists since .NET 2.0, but I suspect they were not documented in MSDN initially, so e.g. I have known this much later.&lt;br /&gt;&lt;br /&gt;Links:&lt;br /&gt;- &lt;a href="http://www.process64.com/OpenDelegatesandClosedDelegates.aspx"&gt;An example&lt;/a&gt;&lt;br /&gt;- &lt;a href="http://msdn.microsoft.com/en-us/library/96b1ayy4.aspx"&gt;Official documentation&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;So what is open delegate? &lt;span style="font-style: italic;"&gt;It is a delegate bound only to a method, but not to an instance, so you can use the same delegate to call the method it is bound to on many instances.&lt;/span&gt; That's it.&lt;br /&gt;&lt;br /&gt;And few more notes:&lt;br /&gt;- Open delegate invocation must take at least the same time as the underlying virtual or interface method invocation, since .NET can't use the same way of invocation as for the regular one (there is no single method call address to use). We didn't test this yet, but if we will, I publish the results here.&lt;br /&gt;- An open delegate bound to virtual generic method must be the slowest one - by the same reason. Do you know why virtual generic methods are the slowest ones? My next post here will explain this.&lt;br /&gt;- Btw, various ways of invocation in .NET are perfectly described &lt;a href="http://www.codeproject.com/KB/cs/net_type_internals.aspx"&gt;here&lt;/a&gt;. The article covers i.e. regular, virtual, interface methods and delegates.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8486822413101972100-1519653532449129643?l=tips.x-tensive.com'/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=3C5H6ybg-do:WAUVH9-FUAY:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=3C5H6ybg-do:WAUVH9-FUAY:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?i=3C5H6ybg-do:WAUVH9-FUAY:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=3C5H6ybg-do:WAUVH9-FUAY:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=3C5H6ybg-do:WAUVH9-FUAY:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?i=3C5H6ybg-do:WAUVH9-FUAY:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://tips.x-tensive.com/feeds/1519653532449129643/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://tips.x-tensive.com/2008/10/open-delegates_8670.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8486822413101972100/posts/default/1519653532449129643?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8486822413101972100/posts/default/1519653532449129643?v=2" /><link rel="alternate" type="text/html" href="http://tips.x-tensive.com/2008/10/open-delegates_8670.html" title="Open delegates" /><author><name>Alex Yakunin</name><uri>http://www.blogger.com/profile/13800929290476802273</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="09650213915253068470" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></entry><entry gd:etag="W/&quot;DUcDQ3k_eyp7ImA9WxRWFE8.&quot;"><id>tag:blogger.com,1999:blog-8486822413101972100.post-355528356697383306</id><published>2008-10-17T16:23:00.008+06:00</published><updated>2008-10-31T09:24:32.743+05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-10-31T09:24:32.743+05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="performance" /><category scheme="http://www.blogger.com/atom/ns#" term="garbage collection" /><category scheme="http://www.blogger.com/atom/ns#" term="finalization" /><title>The cost of having a finalizer</title><content type="html">It's well-known that having a finalizer is costly. But how much does it cost - to have a finalizer?&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;Allocation to nothing:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;- SlimObject: Operations: 77.880 M/s.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;- FinalizableSlimObject: Operations: 1.628 M/s.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;Allocation to an array:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;- SlimObject: Operations: 6.996 M/s.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;- FinalizableSlimObject: Operations: 3.256 M/s.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;"Allocation to nothing" here is allocation without storing a reference anywhere. This case must be the most frequent scenario, since most of allocated objects don't survive the next GC in generation 0.&lt;br /&gt;&lt;br /&gt;There is no any additional GC cost for &lt;span style="font-weight: bold;"&gt;SlimObject&lt;/span&gt; in this case - there are no references to any of such objects, so garbage collector won't mark any of them, and consequently, won't spent any time on them at all.&lt;br /&gt;&lt;br /&gt;But what's with &lt;span style="font-weight: bold;"&gt;FinalizeableSlimObject&lt;/span&gt;?&lt;br /&gt;- &lt;span style="font-style: italic;"&gt;It's allocation is costly, since it is registered for further finalization&lt;/span&gt; (added into a finalization queue). Registration cost must be similar to getting a lock and adding an object to &lt;span style="font-weight: bold;"&gt;Hashtable&lt;/span&gt;.&lt;br /&gt;- &lt;span style="font-style: italic;"&gt;All of such objects are processed (i.e. marked) during the GC&lt;/span&gt;&lt;br /&gt;- &lt;span style="font-style: italic;"&gt;Then they're removed from finalization queue&lt;/span&gt; (~ finding &amp;amp; removing an entry from a &lt;span style="font-weight: bold;"&gt;Hashtable&lt;/span&gt;)&lt;br /&gt;- And &lt;span style="font-style: italic;"&gt;added to FReachable queue&lt;/span&gt; (cheap, ~ adding to a list).&lt;br /&gt;- They're also &lt;span style="font-style: italic;"&gt;processed on heap compaction phase.&lt;/span&gt; We get an additional cost &lt;span style="font-style: italic;"&gt;proportional to the size of an object&lt;/span&gt; here.&lt;br /&gt;- &lt;span style="font-style: italic;"&gt;A separate finalization thread will spend some time on them to finalize them.&lt;/span&gt; This must be not quite noticeable in this test, since the test have been performed on multicore CPU.&lt;br /&gt;- And finally, &lt;span style="font-style: italic;"&gt;if some of them will survive until the next GC in generation 1, we'll will add further overhead&lt;/span&gt; similar to described.&lt;br /&gt;&lt;br /&gt;So as you see, &lt;span style="font-style: italic;"&gt;allocation of short living finalizable object is &lt;/span&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;50 times&lt;/span&gt;&lt;span style="font-style: italic;"&gt; more expensive than of the regular one!&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now let's turn to long-living objects: "Allocation to an array" here is allocation with storing a reference to allocated object in array. The test was running for about a second, so there must be several generation 1 GCs. Certainly &lt;span style="font-weight: bold;"&gt;SlimObject&lt;/span&gt; wins here as well (about &lt;span style="font-weight: bold;"&gt;2 times&lt;/span&gt;), but not as mach as in above case. Why?&lt;br /&gt;- Because all the objects survive many GCs, and GC overhead is the most significant factor for both types of them.&lt;br /&gt;- One more factor slowing down the test with &lt;span style="font-weight: bold;"&gt;SlimObject&lt;/span&gt; is less efficient usage of L1\L2 caches: in first case all the data were "laying" mainly in cache, but here pages must "flow" through the caches. But I suspect this is much less important factor than the first one here.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In any case, probably it's time to finalize some finalizers ;) At least the ones that aren't really necessary.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8486822413101972100-355528356697383306?l=tips.x-tensive.com'/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=BfYDC_t1bIw:v-l4CcT6U7Q:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=BfYDC_t1bIw:v-l4CcT6U7Q:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?i=BfYDC_t1bIw:v-l4CcT6U7Q:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=BfYDC_t1bIw:v-l4CcT6U7Q:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=BfYDC_t1bIw:v-l4CcT6U7Q:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?i=BfYDC_t1bIw:v-l4CcT6U7Q:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://tips.x-tensive.com/feeds/355528356697383306/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://tips.x-tensive.com/2008/10/cost-of-having-finalizer.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8486822413101972100/posts/default/355528356697383306?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8486822413101972100/posts/default/355528356697383306?v=2" /><link rel="alternate" type="text/html" href="http://tips.x-tensive.com/2008/10/cost-of-having-finalizer.html" title="The cost of having a finalizer" /><author><name>Alex Yakunin</name><uri>http://www.blogger.com/profile/13800929290476802273</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="09650213915253068470" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></entry><entry gd:etag="W/&quot;DkAMRHo-fCp7ImA9WxRWEE0.&quot;"><id>tag:blogger.com,1999:blog-8486822413101972100.post-5242968269702564960</id><published>2008-10-16T18:00:00.004+06:00</published><updated>2008-10-26T12:06:25.454+05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-10-26T12:06:25.454+05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="garbage collection" /><category scheme="http://www.blogger.com/atom/ns#" term="memory leaks" /><category scheme="http://www.blogger.com/atom/ns#" term="unknown features" /><title>Dictionary: surprising fact about Remove and Clear methods</title><content type="html">Both these methods never resize internal bucket list of the &lt;span style="font-weight: bold;"&gt;Dictionary&lt;k,v&gt;&lt;/k,v&gt;&lt;/span&gt; - this means dictionary bucket list may only grow up during its lifetime, and the only way to "shrink" it is to recreate the dictionary (create a new one, copy the content of the old one to it and forget the old one).&lt;br /&gt;&lt;br /&gt;To get the approval of this fact, study the source code of both methods - e.g. with &lt;a href="http://reflector.red-gate.com/"&gt;.NET Reflector&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8486822413101972100-5242968269702564960?l=tips.x-tensive.com'/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=M2mI_kT9LYI:u8JXBf3E_PM:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=M2mI_kT9LYI:u8JXBf3E_PM:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?i=M2mI_kT9LYI:u8JXBf3E_PM:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=M2mI_kT9LYI:u8JXBf3E_PM:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=M2mI_kT9LYI:u8JXBf3E_PM:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?i=M2mI_kT9LYI:u8JXBf3E_PM:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://tips.x-tensive.com/feeds/5242968269702564960/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://tips.x-tensive.com/2008/10/dictionary-surprising-fact-about-remove.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8486822413101972100/posts/default/5242968269702564960?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8486822413101972100/posts/default/5242968269702564960?v=2" /><link rel="alternate" type="text/html" href="http://tips.x-tensive.com/2008/10/dictionary-surprising-fact-about-remove.html" title="Dictionary&lt;K,V&gt;: surprising fact about Remove and Clear methods" /><author><name>Alex Yakunin</name><uri>http://www.blogger.com/profile/13800929290476802273</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="09650213915253068470" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></entry><entry gd:etag="W/&quot;DUYEQ3w4eip7ImA9WxRWFE8.&quot;"><id>tag:blogger.com,1999:blog-8486822413101972100.post-5752611514431364485</id><published>2008-10-16T12:31:00.007+06:00</published><updated>2008-10-31T09:25:02.232+05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-10-31T09:25:02.232+05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="performance" /><category scheme="http://www.blogger.com/atom/ns#" term="thread safety" /><category scheme="http://www.blogger.com/atom/ns#" term="unknown features" /><title>When Hashtable is better than Dictionary</title><content type="html">We all know &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Hashtable&lt;/span&gt; class - it exists in .NET from the very beginning. .NET 2.0 has brought a generic replacement to it: &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Dictionary.&lt;k,v&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt; So we usually prefer using it rather than &lt;/span&gt;Hashtable&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;. But it isn't well known &lt;/span&gt;Hashtable&lt;span class="Apple-style-span" style="font-weight: normal;"&gt; has a very nice feature related to concurrent usage, which &lt;/span&gt;Dictionary&lt;span class="Apple-style-span" style="font-weight: normal;"&gt; does not have (at least by documentation):&lt;/span&gt;&lt;/k,v&gt;&lt;/span&gt;&lt;div&gt;- &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Hashtable&lt;/span&gt; supports &lt;span class="Apple-style-span" style="font-style: italic;"&gt;single writer &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;and&lt;/span&gt; multiple readers&lt;/span&gt; concurrent access policy&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;k,v&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;- But &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Dictionary&lt;/span&gt; - standard &lt;span class="Apple-style-span" style="font-style: italic;"&gt;single writer &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;or&lt;/span&gt; multiple readers &lt;/span&gt;&lt;/span&gt;&lt;/k,v&gt;&lt;/span&gt;concurrent access policy&lt;div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This means usage of &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Hashtable&lt;/span&gt; is perfect e.g. in concurrent caching scenarios: only write operations on it require locking to ensure thread safety, but in case with &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Dictionary&lt;/span&gt; both read and write operations require locking.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The official "approval" of this fact is &lt;a href="http://msdn.microsoft.com/en-us/library/system.collections.hashtable.aspx"&gt;here&lt;/a&gt;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;And a fly in the ointment:&lt;/div&gt;&lt;div&gt;- It's difficult to find out if this was fully correct for .NET 2.0, since this fact was mentioned only recently. The issue report related to this is &lt;a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=269447"&gt;here&lt;/a&gt;.&lt;/div&gt;&lt;div&gt;- This is not completely true:&lt;span&gt;&lt;span&gt; &lt;a href="http://blogs.msdn.com/brada/archive/2003/04/13/49969.aspx"&gt;here&lt;/a&gt; is the report. &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Possible workarounds:&lt;/div&gt;&lt;div&gt;- Never clear or remove items from &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Hashtable&lt;/span&gt; at all. In many cases this is ok, e.g. when you cache something for a lifetime of the cache or the whole application. An example is caching of &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Reflection.Emit&lt;/span&gt; results or any other code loaded into &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;AppDomain&lt;/span&gt;: you anyway can't unload the code, so there is no reason to clean up any references to it from caches.&lt;/div&gt;&lt;div&gt;- Implement item removal by dropping the old &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Hashtable&lt;/span&gt; and copying its content (without the item to remove) to a new one. Or implement a wrapper doing the same using two &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Hashtable&lt;/span&gt;s (one contains just added keys and values, and andother one just removed keys) and periodically doing the garbage collection be re-creating both of them as described above. But actually the cost of looking into two &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Hashtable&lt;/span&gt;s must be close to the cost of locking.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In any case, this feature is very nice even with all the mentioned problems. We utilize this feature of &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Hashtable&lt;/span&gt; e.g. in our &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;ThreadSafeDictionary&lt;/span&gt; class.&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8486822413101972100-5752611514431364485?l=tips.x-tensive.com'/&gt;&lt;/div&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=BW_aPGd86FY:HKu3k3vsy7M:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=BW_aPGd86FY:HKu3k3vsy7M:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?i=BW_aPGd86FY:HKu3k3vsy7M:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=BW_aPGd86FY:HKu3k3vsy7M:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/dotNetTips?a=BW_aPGd86FY:HKu3k3vsy7M:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/dotNetTips?i=BW_aPGd86FY:HKu3k3vsy7M:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://tips.x-tensive.com/feeds/5752611514431364485/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://tips.x-tensive.com/2008/10/when-hashtable-is-better-then.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/8486822413101972100/posts/default/5752611514431364485?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/8486822413101972100/posts/default/5752611514431364485?v=2" /><link rel="alternate" type="text/html" href="http://tips.x-tensive.com/2008/10/when-hashtable-is-better-then.html" title="When Hashtable is better than Dictionary" /><author><name>Alex Yakunin</name><uri>http://www.blogger.com/profile/13800929290476802273</uri><email>noreply@blogger.com</email><gd:extendedProperty name="OpenSocialUserId" value="09650213915253068470" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total></entry></feed>
