<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Channel 9 - Discussions by ktr</title>
	<atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Niners/ktr/Discussions/RSS"></atom:link>
	<image>
		<url>http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.png</url>
		<title>Channel 9 - Discussions by ktr</title>
		<link>http://channel9.msdn.com/Niners/ktr/Discussions</link>
	</image>
	<description>Channel 9 keeps you up to date with the latest news and behind the scenes info from Microsoft that developers love to keep up with. From LINQ to SilverLight – Watch videos and hear about all the cool technologies coming and the people behind them.</description>
	<link>http://channel9.msdn.com/Niners/ktr/Discussions</link>
	<language>en</language>
	<pubDate>Sun, 26 May 2013 04:52:44 GMT</pubDate>
	<lastBuildDate>Sun, 26 May 2013 04:52:44 GMT</lastBuildDate>
	<generator>Rev9</generator>
	<c9:totalResults>0</c9:totalResults>
	<c9:pageCount>0</c9:pageCount>
	<c9:pageSize>0</c9:pageSize>
	<item>
		<title>Coffeehouse - Anders Interview next week: Ask Questions Here</title>
		<description><![CDATA[<p>With the future addition of &quot;compiler as a service&quot; are there any plans for possible support for metaprogramming? Like possible IDE support for templating in a way that is integrated into the C# language itself?</p><p>I think this would make the bar much lower for creating frameworks that are both dynamic and yet very performant as well.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/Coffeehouse/Anders-Interview-next-week-Ask-Questions-Here/9fd6f06df36148e4b3f69ecd0010e24e#9fd6f06df36148e4b3f69ecd0010e24e</link>
		<pubDate>Fri, 22 Apr 2011 01:01:28 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/Coffeehouse/Anders-Interview-next-week-Ask-Questions-Here/9fd6f06df36148e4b3f69ecd0010e24e#9fd6f06df36148e4b3f69ecd0010e24e</guid>
		<dc:creator>ktr</dc:creator>
		<slash:comments>34</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ktr/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Coffeehouse - Anders Interview next week: Ask Questions Here</title>
		<description><![CDATA[<p>Is there any update on the status of extension properties? Last I heard, they weren't going to be supported due to a lack of acceptable syntax.</p><p>Would there ever be consideration for a syntax that allows declaration of extension methods/properties via a different kind of class definition?</p><p>For example:</p><p><pre class="brush: csharp">
// extension class
// can only access public members of parent type
// only methods and properties can be defined; no fields
public extension class ListExtensions&lt;T&gt; : List&lt;T&gt; 
{

  // extension method
  public int foo() 
  {
    /* ... */
    return this.size(); // this refers to any List&lt;T&gt; instance.
  }

  // extension property
  public int bar
  {
    get { /* ... */ return this.size(); }
    set { /* ... */ }
  }

}</pre></p><p>I think it would be a nice thing to have. And in the future it would give any other additions to the &quot;extension&quot; concept a nice home.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/Coffeehouse/Anders-Interview-next-week-Ask-Questions-Here/9d36c04dcd1444c3b8809ecd000f9951#9d36c04dcd1444c3b8809ecd000f9951</link>
		<pubDate>Fri, 22 Apr 2011 00:56:47 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/Coffeehouse/Anders-Interview-next-week-Ask-Questions-Here/9d36c04dcd1444c3b8809ecd000f9951#9d36c04dcd1444c3b8809ecd000f9951</guid>
		<dc:creator>ktr</dc:creator>
		<slash:comments>34</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ktr/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Coffeehouse - Why No Computer Science&quot;y&quot; Books in C#?</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">Sven Groot said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">vesuvius said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>Oh I agree with that. CS students should learn about the unmanaged side of things too. Whether it's sane to start out with C&#43;&#43; though, I don't know. My university was strictly C&#43;&#43; in first year, and way too much time was spent by people trying to figure
 out C&#43;&#43; the language rather than the problem they were trying to solve. This was even more apparent when I was assistant for&nbsp;that very same first year class a few years later.</p>
<p>&nbsp;</p>
<p>However, the main issue I was getting at before is that you said you exclude C# because it's managed, yet you did put Java on the list in an earlier post.</p>
</div></blockquote>
<p>I tend to agree that since C# has introduced several new paradigms (functional, declarative, dynamic, etc...), it has become the best language for the majority of projects out there.</p>
<p>&nbsp;</p>
<p>However, with all these new capabilities comes complexity. &nbsp;For a CS student with no experience with programming languages, C# is generally (IMHO) not a good first language. &nbsp;The language is so powerful and broad now that it is hard to know where to start
 if you've never been exposed to programming.</p>
<p>&nbsp;</p>
<p>C# has had a flood of innovation (LINQ, lambdas, dynamic programming, extension methods, etc...). &nbsp;Not to mention all of the additional features that C# 1.0 had over Java (delegates, properties, etc...). &nbsp;The truth is that to you and me C# is beautiful but
 to a beginner it is simply daunting.</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/Coffeehouse/532873-Why-No-Computer-Sciencey-Books-in-C/2ccb2895795f44cd819c9deb00d9eb73#2ccb2895795f44cd819c9deb00d9eb73</link>
		<pubDate>Sun, 28 Feb 2010 20:29:01 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/Coffeehouse/532873-Why-No-Computer-Sciencey-Books-in-C/2ccb2895795f44cd819c9deb00d9eb73#2ccb2895795f44cd819c9deb00d9eb73</guid>
		<dc:creator>ktr</dc:creator>
		<slash:comments>21</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ktr/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - CSharp thread</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">Sven Groot said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">ktr said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>Yeah, I thought of that after posting it, but couldn't be arsed to change it. <img src="http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-5.gif" alt="Wink"></p>
<p>&nbsp;</p>
<p>Note that if you do that, you should calculate start incrementally by adding count, not&nbsp;the way it's&nbsp;done now.</p>
</div></blockquote>
<p>Ah, true.</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/530198-C-thread/90adbd5dc60b4ff589389deb000c4d14#90adbd5dc60b4ff589389deb000c4d14</link>
		<pubDate>Fri, 26 Feb 2010 02:35:17 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/530198-C-thread/90adbd5dc60b4ff589389deb000c4d14#90adbd5dc60b4ff589389deb000c4d14</guid>
		<dc:creator>ktr</dc:creator>
		<slash:comments>21</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ktr/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - CSharp thread</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">Sven Groot said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">cro said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>I think you'll have to use wait handles (in this case I'm using ManualResetEvent which is the most appropriate here I think):</p>
<p>&nbsp;</p>
<p></p>
<pre class="brush: text">public static void ComputeUnits(Unit[] units)
{
    int threadCount = Environment.ProcessorCount;
    int unitsPerThread = units.Length / threadCount;
    int remainder = units.Length % threadCount;
    ManualResetEvent[] evts = new ManualResetEvent[threadCount];

    try
    {
        for( int t = 0; t &lt; threadCount; &#43;&#43;t )
        {
            evts[t] = new ManualResetEvent(false);

            int count = unitsPerThread;
            if( t == threadCount - 1 )
                count &#43;= remainder; // Give the last thread the remainder

            int start = t * unitsPerThread;
            ManualResetEvent evt = evts[t]
            ThreadPool.QueueUserWorkItem(obj =&gt; ComputeThread(units, start, count, evt));
        }

        WaitHandle.WaitAll(evts);
    }
    finally
    {
        foreach( ManualResetEvent evt in evts )
            evt.Dispose();
    }
}

private static void ComputeThread(Unit[] units, int start, int count, ManualResetEvent evt)
{
    for( int x = start; x &lt; start &#43; count; &#43;&#43;x )
        Compute(units[x]);
    evt.Set();
}</pre>
<p></p>
<p>&nbsp;</p>
<p>Note: never, ever do this if ComputeUnits itself is on a thread pool thread. Waiting on a thread pool thread from another thread pool thread can cause deadlock.</p>
</div></blockquote>
<p>&nbsp;</p>
<div id="_mcePaste">Maybe you could change this:</div>
<div id="_mcePaste">if (t == threadCount - 1) &nbsp;count &#43;= remainder; // give the last thread the remainder</div>
<div id="_mcePaste">to this:</div>
<div id="_mcePaste">if (t &lt; remainder) count&#43;&#43;; // evenly distribute remainder</div>
<p>&nbsp;</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/530198-C-thread/fa475fcc72ec49bcbab29deb000c4cbc#fa475fcc72ec49bcbab29deb000c4cbc</link>
		<pubDate>Thu, 25 Feb 2010 22:39:51 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/530198-C-thread/fa475fcc72ec49bcbab29deb000c4cbc#fa475fcc72ec49bcbab29deb000c4cbc</guid>
		<dc:creator>ktr</dc:creator>
		<slash:comments>21</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ktr/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Coffeehouse - Windows 7 was *my* idea</title>
		<description><![CDATA[<p>That's hilarious.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/Coffeehouse/532128-Windows-7-was-my-idea/22c72494fa6c45a09ded9deb00d99d4b#22c72494fa6c45a09ded9deb00d99d4b</link>
		<pubDate>Wed, 24 Feb 2010 18:00:50 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/Coffeehouse/532128-Windows-7-was-my-idea/22c72494fa6c45a09ded9deb00d99d4b#22c72494fa6c45a09ded9deb00d99d4b</guid>
		<dc:creator>ktr</dc:creator>
		<slash:comments>21</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ktr/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Ideas for C# 5.0</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">BitFlipper said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">exoteric said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>Well, if you look at&nbsp;anonymous methods&nbsp;and captured variables etc, the compiler already creates anonymous classes in that case as you mention. We don't really care too much about the signature of these classes, since they are mostly hidden from us (although
 you can certainly see them in the debugger). In addition, when you use IEnumerable and yield return, the compiler infers the type from the return value. So if you combine those two concepts, you can basically have tuples with named items, right?</p>
<p>&nbsp;</p>
<p>So in my example, the type of &quot;result&quot;, would be&nbsp;something like &quot;&lt;Tuple&gt;a__1&quot; or whatever, but it would contain the&nbsp;public members&nbsp;with the correct names and types. Edit: And this is also what you would see if you used reflection to query the enclosing class's
 properties.</p>
<p>&nbsp;</p>
<p>BTW, in my example then it&nbsp;should really be returned like this:</p>
<p>&nbsp;</p>
<p><span class="keyword"></p>
<pre class="brush: text">public ITuple Result
{ 
    get { return (Count = runCount, Min = runMin, Max = runMax, Avg = runAvg); } 
}</pre>
</span>
<p></p>
<p>&nbsp;</p>
<p><span class="keyword">So just like you use IEnumerable when using yield return, you use ITuple, and the return type determines its true signature.</span></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</div></blockquote>
<p>This is very similar to anonymous types:</p>
<p>&nbsp;</p>
<p></p>
<pre class="brush: csharp">var x = new { Count = runCount, Min = runMin, Max = runMax, Avg = runAvg };</pre>
<p></p>
<p>&nbsp;</p>
<p>The only difference is that anonymous types can only be used in a local scope. &nbsp;I think that you should be able to return them from methods. &nbsp;It is still just as type-safe but a lot more succinct:</p>
<p>&nbsp;</p>
<p></p>
<pre class="brush: csharp">public var GetAnonymous() {
  return new { Count = runCount, Min = runMin, Max = runMax, Avg = runAvg };
}</pre>
<p></p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/499699-Suggestions-for-C-50/1cbb857ee93e411f98649deb00098f06#1cbb857ee93e411f98649deb00098f06</link>
		<pubDate>Wed, 24 Feb 2010 17:53:44 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/499699-Suggestions-for-C-50/1cbb857ee93e411f98649deb00098f06#1cbb857ee93e411f98649deb00098f06</guid>
		<dc:creator>ktr</dc:creator>
		<slash:comments>131</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ktr/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Extensia</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">W3bbo said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">exoteric said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>Methods for working with lists to allow editing them within foreach loops without needing to manage a separate itemsToRemove list yourself:</p>
<p>&nbsp;</p>
<p>Because C# 3.0 doesn't support generic covariance I couldn't avoid using the Object type in the dictionary.</p>
<p>&nbsp;</p>
<p></p>
<pre class="brush: csharp"> // how do you do a Dictionary&lt;List&lt;T&gt;,List&lt;T&gt;&gt; where T is unknown? the CLR doesn't support generic inheritance (So you can't do Dictionary&lt;List&lt;Object&gt;,List&lt;Object&gt;&gt; *AND* ensure Object == Object too) private static Dictionary&lt;Object,Object&gt;
 _pendingRemovals = new Dictionary&lt;Object,Object&gt;(); private static List&lt;T&gt; GetPendingRemovals&lt;T&gt;(IList&lt;T&gt; list) { if( !_pendingRemovals.ContainsKey( list ) ) _pendingRemovals.Add( list, new List&lt;T&gt;() ); List&lt;T&gt; pendingRemovals = (List&lt;T&gt;)_pendingRemovals[
 list ]; return pendingRemovals; } /// &lt;summary&gt;Removes &lt;paramref name=&quot;removeThis&quot;/&gt; from the list when RemoveCommit is called.&lt;/summary&gt; public static void RemovePending&lt;T&gt;(this IList&lt;T&gt; list, T removethis) { List&lt;T&gt; pendingRemovals = GetPendingRemovals(
 list ); pendingRemovals.Add( removethis ); } /// &lt;summary&gt;Removes all pending items from the list&lt;/summary&gt; public static void RemoveCommit&lt;T&gt;(this IList&lt;T&gt; list) { List&lt;T&gt; pendingRemovals = GetPendingRemovals( list ); foreach(T item in pendingRemovals) {
 list.Remove( item ); } _pendingRemovals.Remove( list ); } /// &lt;summary&gt;Cancels all pending item removals from &lt;param name=&quot;list&quot; /&gt;&lt;/summary&gt; public static void RemoveCancel&lt;T&gt;(this IList&lt;T&gt; list) { _pendingRemovals.Remove( list ); } /// &lt;summary&gt;Cancels a
 particular pending removal.&lt;/summary&gt; public static void RemoveCancel&lt;T&gt;(this IList&lt;T&gt; list, T dontRemoveThis) { List&lt;T&gt; pendingRemovals = GetPendingRemovals( list ); pendingRemovals.Remove( dontRemoveThis ); }</pre>
<p></p>
<p>&nbsp;</p>
<p>Usage: </p>
<p></p>
<pre class="brush: csharp">List&lt;Bar&gt; bar = GetBarList(); foreach(Foo foo in bar) { if( foo.NeedsDeleting ) bar.PendingRemove( foo ); } bar.PendingCommit();</pre>
<p></p>
</div></blockquote>
<p>That's pretty cool. &nbsp;I prefer a different approach, however.</p>
<p>&nbsp;</p>
<p><pre class="brush: csharp">public static void RemoveWhere&lt;T&gt;(this IList&lt;T&gt; list, Func&lt;T, bool&gt; where) { for (int i = 0; i &lt; list.Count; i&#43;&#43;) if (where(list[i])) list.RemoveAt(i--); } //... var list = new List&lt;string&gt; { &quot;Jon&quot;, &quot;Bob&quot;, &quot;Joe&quot;, &quot;Herb&quot;, &quot;Billy&quot;,
 &quot;Boe&quot; }; list.RemoveWhere(s =&gt; s.StartsWith(&quot;B&quot;)); // results in { &quot;Jon&quot;, &quot;Joe&quot;, &quot;Herb&quot; }</pre></p>
<p>&nbsp;</p>
<p>EDIT: Haha, and apparently the library designers agree. &nbsp;List&lt;T&gt; already defines a
<strong>RemoveAll </strong>method that does the same thing. &nbsp;To be fair though, this works on any IList&lt;T&gt;.</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/489157-Extensia/2ad4f9e5bc6140abb7eb9deb0008a89f#2ad4f9e5bc6140abb7eb9deb0008a89f</link>
		<pubDate>Sat, 20 Feb 2010 14:07:15 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/489157-Extensia/2ad4f9e5bc6140abb7eb9deb0008a89f#2ad4f9e5bc6140abb7eb9deb0008a89f</guid>
		<dc:creator>ktr</dc:creator>
		<slash:comments>78</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ktr/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Enums are expensive in dictionaries?</title>
		<description><![CDATA[<p>You should use an array. Just make your enum values equal to the corresponding indices.</p>
<p>&nbsp;</p>
<p></p>
<pre class="brush: csharp">enum FlyState {
  State1 = 0,
  State2 = 1,
  // ...
}
// ...
var flyStateColors = new Color[Enum.GetValues(typeof(FlyState)).Length];
// or
var flyStateColors = new Color[/* hardcoded value */];
// set a value
flyStateColors[(int)FlyState.State1] = Color.FromArgb(255, 0, 0);
// get a value
var color = flyStateColors[(int)someFlyState];</pre>
<p></p>
<p>&nbsp;</p>
<p>You could even make extension methods to get/set values of a color array based on FlyState values instead of integer indices.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/504120-Enums-are-expensive-in-dictionaries/618ca295ecb94f2aac7b9deb000a169a#618ca295ecb94f2aac7b9deb000a169a</link>
		<pubDate>Tue, 03 Nov 2009 20:27:49 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/504120-Enums-are-expensive-in-dictionaries/618ca295ecb94f2aac7b9deb000a169a#618ca295ecb94f2aac7b9deb000a169a</guid>
		<dc:creator>ktr</dc:creator>
		<slash:comments>13</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ktr/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - How do you hide properties?</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">ktr said:</div><div class="quoteText">
<p></p>
<pre class="brush: text">using System.Windows.Forms; using System.ComponentModel; namespace Test2 { class ProgressBar2 : ProgressBar { [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
 public new bool TabStop { get { return ((Control)this).TabStop; } set { ((Control)this).TabStop = value; } } } } </pre>
<p></p>
</div></blockquote>
<p>Also, this won't hide the property from intellisense unless the project you are working on lives in a different DLL from the control. &nbsp;You also can't have the project that the control lives in open in the same VS instance, otherwise intellisense will pick
 it up.</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/489312-How-do-you-hide-properties/4442b3da3c5f4866ae3b9deb0008af18#4442b3da3c5f4866ae3b9deb0008af18</link>
		<pubDate>Thu, 03 Sep 2009 00:17:30 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/489312-How-do-you-hide-properties/4442b3da3c5f4866ae3b9deb0008af18#4442b3da3c5f4866ae3b9deb0008af18</guid>
		<dc:creator>ktr</dc:creator>
		<slash:comments>4</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ktr/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - How do you hide properties?</title>
		<description><![CDATA[<p><pre class="brush: text">using System.Windows.Forms; using System.ComponentModel; namespace Test2 { class ProgressBar2 : ProgressBar { [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
 public new bool TabStop { get { return ((Control)this).TabStop; } set { ((Control)this).TabStop = value; } } } } </pre></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/489312-How-do-you-hide-properties/9c803eb5118b4fb49f809deb0008aef1#9c803eb5118b4fb49f809deb0008aef1</link>
		<pubDate>Wed, 02 Sep 2009 23:56:31 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/489312-How-do-you-hide-properties/9c803eb5118b4fb49f809deb0008aef1#9c803eb5118b4fb49f809deb0008aef1</guid>
		<dc:creator>ktr</dc:creator>
		<slash:comments>4</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ktr/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Features you like added to vb.net, c#  or any other .net language.</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">sysrpl said:</div><div class="quoteText">
<p>Virtual constructors.</p>
<p>// public virtual SampleObject(string name)&nbsp; {&nbsp; }</p>
<p>&nbsp;</p>
<p>Virtual static methods.</p>
<p>// public static virtual DoSomething() { }</p>
<p>&nbsp;</p>
<p>Virtual static constructors.</p>
<p>&nbsp;// public static virtual SampleObject(string name)&nbsp; {&nbsp; }</p>
<p>&nbsp;</p>
<p>Enumeration set operations.</p>
<p>// textBox.Anchors &#43;= { AnchorStyles.Right, AnchorStyles.Bottom };</p>
<p>&nbsp;</p>
<p>Implementation through delegation.</p>
<p>// public class SomeItems : IList&lt;SomeItem&gt; { private List&lt;SomeItem&gt; items; private implements IList&lt;SomeItem&gt; GetList() { return items; }&nbsp; }</p>
<p>&nbsp;</p>
<p>Static method extensions.</p>
<p>// public static void DoSomething(this SomeType, string message);</p>
<p>&nbsp;</p>
<p>Property extensions.</p>
<p>// public string FunnyName { this SomeType; get; set; }</p>
<p>&nbsp;</p>
<p>Static property extensions.</p>
<p>// public static string FunnyName { this SomeType; get; set; }</p>
<p>&nbsp;</p>
<p>Type aliases.</p>
<p>// public typedef SomeItemList = List&lt;SomeItem&gt;;</p>
<p>&nbsp;</p>
<p>Expando properties and methods.</p>
<p>// instance.SomeNewProperty = 12; instance.SomeNewMethod = (string message) =&gt; MessageBox.Show(message);</p>
<p>&nbsp;</p>
<p>Class references.</p>
<p>// public SomeItemClass = class of SomeItem;</p>
<p>&nbsp;</p>
<p>Message based dynamic methods.</p>
<p>// public message(1) void DoSomething(ref MessageArgs messageArgs) { }</p>
<div id="_mcePaste">instance.</div>
</div></blockquote>
<p>@sysrpl</p>
<p>&quot;Expando properties and methods.</p>
<p>// instance.SomeNewProperty = 12; instance.SomeNewMethod = (string message) =&gt; MessageBox.Show(message);&quot;</p>
<p>&nbsp;</p>
<p>I don't know... Perhaps only in a dynamic context?</p>
<p>&nbsp;</p>
<p><pre class="brush: csharp">dynamic instance = GetInstance();
instance.SomeNewProperty = 12;
instance.SomeNewMethod = (string message) =&gt; MessageBox.Show(message);</pre></p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/484956-Features-you-like-added-to-vbnet-c-or-any-other-net-language/805f43a9f8544301a0999deb0008040a#805f43a9f8544301a0999deb0008040a</link>
		<pubDate>Mon, 31 Aug 2009 02:42:19 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/484956-Features-you-like-added-to-vbnet-c-or-any-other-net-language/805f43a9f8544301a0999deb0008040a#805f43a9f8544301a0999deb0008040a</guid>
		<dc:creator>ktr</dc:creator>
		<slash:comments>28</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ktr/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Features you like added to vb.net, c#  or any other .net language.</title>
		<description><![CDATA[<p>@AndyC</p>
<p>&quot;You do know you can just use ToString() on an enum to get it's value in string form?&quot;</p>
<p>&nbsp;</p>
<p>That's true, but the naming rules for enums don't capture all of unicode &nbsp;<img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-4.gif' alt='Tongue Out' /> </p>
<p><a href="http://channel9.msdn.com/forums/Coffeehouse/257556-C-Extension-Properties/"></a></p>
<p><a href="http://channel9.msdn.com/forums/Coffeehouse/257556-C-Extension-Properties/"></a></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/484956-Features-you-like-added-to-vbnet-c-or-any-other-net-language/bd72577747d94eae80d99deb000802c7#bd72577747d94eae80d99deb000802c7</link>
		<pubDate>Sun, 30 Aug 2009 01:31:39 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/484956-Features-you-like-added-to-vbnet-c-or-any-other-net-language/bd72577747d94eae80d99deb000802c7#bd72577747d94eae80d99deb000802c7</guid>
		<dc:creator>ktr</dc:creator>
		<slash:comments>28</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ktr/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Features you like added to vb.net, c#  or any other .net language.</title>
		<description><![CDATA[<p><div>I obviously don't expect all of this, but it would be nice.</div>
<ul>
<li><a href="http://channel9.msdn.com/forums/Coffeehouse/257556-C-Extension-Properties/">Extension Properties</a>&nbsp;
</li><li><a href="http://dotnet.dzone.com/news/introduction-mixins-c">Mixins</a> </li><li>Language support for tuple types:<br /><pre class="brush: csharp">public (int, string) GetSomeTuple() { /* ... */ }</pre>Perhaps this could even extend to tuples with named properties (much like anonymous types):<br /><pre class="brush: csharp">public (int Age, string Name) GetSomeTuple() { /* .. */ }</pre>
</li><li>Better language support for function types (unlimited args, named args) </li><li>More type inference! this leads to my final request... </li><li>Better support for anonymous types&nbsp;(shouldn't be limited to only a local scope):<br /><pre class="brush: csharp">public anonymous GetSomeObject() { return new { Feature = &quot;Anonymous Types&quot;, Version = 2 } }</pre><br />Still strongly typed, just a lot simpler. </li></ul></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/484956-Features-you-like-added-to-vbnet-c-or-any-other-net-language/76290c98dac4494fb9c89deb000802a0#76290c98dac4494fb9c89deb000802a0</link>
		<pubDate>Sun, 30 Aug 2009 01:30:40 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/484956-Features-you-like-added-to-vbnet-c-or-any-other-net-language/76290c98dac4494fb9c89deb000802a0#76290c98dac4494fb9c89deb000802a0</guid>
		<dc:creator>ktr</dc:creator>
		<slash:comments>28</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ktr/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Regular Expression to remove an attribute</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">Sven Groot said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">ktr said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>Visual Studio's find dialog uses a&nbsp;different regex syntax. This ought to do the trick:</p>
<p>&nbsp;</p>
<p>:b&#43;x\:Uid=&quot;[^&quot;]&#43;&quot;</p>
</div></blockquote>
<p>Not when there are newlines between the quotes.</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/485161-Regular-Expression-to-remove-an-attribute/d9b723da1d70455a813a9deb000812fa#d9b723da1d70455a813a9deb000812fa</link>
		<pubDate>Sat, 15 Aug 2009 03:51:16 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/485161-Regular-Expression-to-remove-an-attribute/d9b723da1d70455a813a9deb000812fa#d9b723da1d70455a813a9deb000812fa</guid>
		<dc:creator>ktr</dc:creator>
		<slash:comments>11</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ktr/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Regular Expression to remove an attribute</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">ktr said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">Harlequin said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>Hmm.. that is strange. &nbsp;That is definitely the right expression. &nbsp;It works with C#'s regex engine and Javascript's engine too. &nbsp;I tried using it in VS2008's find dialog and I got the same error. &nbsp;I don't know how to fix that. &nbsp;I think they have some custom
 searches you can perform that are prefixed with a colon. &nbsp;That kind of botches the regex functionality...</p>
</div></blockquote>
<p>Ok.. i finally figured it out... VS has a different syntax for finding whitespace (<strong>:Wh</strong>). &nbsp;Anyway, here it is (this will only work in the find dialog):</p>
<p>&nbsp;</p>
<p>:Whx\:Uid=&quot;([^&quot;]|:Wh)*&quot;</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/485161-Regular-Expression-to-remove-an-attribute/880cadbd85c24487a0ff9deb000812a9#880cadbd85c24487a0ff9deb000812a9</link>
		<pubDate>Sat, 15 Aug 2009 03:45:46 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/485161-Regular-Expression-to-remove-an-attribute/880cadbd85c24487a0ff9deb000812a9#880cadbd85c24487a0ff9deb000812a9</guid>
		<dc:creator>ktr</dc:creator>
		<slash:comments>11</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ktr/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Regular Expression to remove an attribute</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">Harlequin said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">ktr said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>Unknown operator on the :</p>
<p>&nbsp;</p>
<p>Might need an escape or something?</p>
</div></blockquote>
<p>Hmm.. that is strange. &nbsp;That is definitely the right expression. &nbsp;It works with C#'s regex engine and Javascript's engine too. &nbsp;I tried using it in VS2008's find dialog and I got the same error. &nbsp;I don't know how to fix that. &nbsp;I think they have some custom
 searches you can perform that are prefixed with a colon. &nbsp;That kind of botches the regex functionality...</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/485161-Regular-Expression-to-remove-an-attribute/8ef0ff087f854a1daf629deb00081280#8ef0ff087f854a1daf629deb00081280</link>
		<pubDate>Sat, 15 Aug 2009 03:06:56 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/485161-Regular-Expression-to-remove-an-attribute/8ef0ff087f854a1daf629deb00081280#8ef0ff087f854a1daf629deb00081280</guid>
		<dc:creator>ktr</dc:creator>
		<slash:comments>11</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ktr/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - Regular Expression to remove an attribute</title>
		<description><![CDATA[<p>Regex:</p>
<p>\s&#43;x:Uid=\&quot;[^\&quot;]&#43;\&quot;</p>
<p>&nbsp;</p>
<p>in C#:</p>
<p>var regex = &quot;\\s&#43;x:Uid=\\\&quot;[^\\\&quot;]&#43;\\\&quot;&quot;;</p>
<p>... try that</p>
<p>&nbsp;</p>
<p>Edit: Updated regex.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/485161-Regular-Expression-to-remove-an-attribute/6548d404baca403b839d9deb00081232#6548d404baca403b839d9deb00081232</link>
		<pubDate>Fri, 14 Aug 2009 21:12:05 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/485161-Regular-Expression-to-remove-an-attribute/6548d404baca403b839d9deb00081232#6548d404baca403b839d9deb00081232</guid>
		<dc:creator>ktr</dc:creator>
		<slash:comments>11</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ktr/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Coffeehouse - API Calls and XML Objects with C#</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">Cybermagellan said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">Cybermagellan said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
I'm kinda stuck and before when I was at AOL this issue was bypassed by our API but...I digress.<br>
<br>
I have my object and i'm chugging along....something&nbsp;isn't working and I think I might be missing the wrong implementation...<br>
<br>
Off the Twitter response I'm doing....<br>
<br>
<p>xDocument.Descendants(&quot;status&quot;)</p>
<br>
and that works just fine....but status has another decendant of user....that I need some data from....so the XMLObject looks like...<br>
<br>
&lt;status&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&lt;blah&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&lt;blah&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&lt;blah&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;user&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;name&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;screen_name&gt;<br>
<br>
I can get anything under status, but trying to get the name I'm not able to....<br>
<br>
I tried status.Decendants(&quot;name&quot;).Value but that didn't work....I'm sure it's something simple but I can't figure it out...any help? I also tried NextNode, and some other things and nothing.<br>
<br>
EDIT: Figures after I posted I&nbsp;find what I wanted....<br>
<br>
foreach(var node in doc.Elements(&quot;employees&quot;).Elements(&quot;employee&quot;).Elements(&quot;name&quot;))<br>
<br>
^- This actually works? it kinda made sense just never seen it before....<br>
</div></blockquote>This works for me:<br>
<u><br>
XML File (test.xml)</u><br>
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;<br>
&lt;root&gt;<br>
&nbsp; &lt;status&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;blah&gt;Doe a deer&lt;/blah&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;user&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;name&gt;John Doe&lt;/name&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;screen_name&gt;jdoe&lt;/screen_name&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;/user&gt;<br>
&nbsp; &lt;/status&gt;<br>
&nbsp; &lt;status&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;blah&gt;Billy dilly&lt;/blah&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;user&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;name&gt;Billy Bob&lt;/name&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;screen_name&gt;bbob&lt;/screen_name&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;/user&gt;<br>
&nbsp; &lt;/status&gt;<br>
&lt;/root&gt;<br>
<br>
<u>C# code:</u><br>
<b>var </b>document = XDocument.Load(&quot;../../test.xml&quot;);<br>
<br>
<b>var </b>status =<br>
&nbsp; <b>from </b>s <b>in </b>document.Descendants(&quot;status&quot;)<br>
&nbsp; <b>let </b>u = s.Element(&quot;user&quot;)<br>
&nbsp; <b>select new </b>{<br>
&nbsp;&nbsp;&nbsp; Blah = s.Element(&quot;blah&quot;).Value,<br>
&nbsp;&nbsp;&nbsp; // ...<br>
&nbsp;&nbsp;&nbsp; // load other elements in here<br>
&nbsp;&nbsp;&nbsp; // ...<br>
&nbsp;&nbsp;&nbsp; User = <b>new </b>{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Name = u.Element(&quot;name&quot;).Value,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ScreenName = u.Element(&quot;screen_name&quot;).Value<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp; };<br>
<br>
<b>foreach </b>(<b>var </b>s <b>in </b>status) {<br>
&nbsp; Console.WriteLine(s.Blah);<br>
&nbsp; Console.WriteLine(&quot;&nbsp; - {0} ({1})&quot;, s.User.Name, s.User.ScreenName);<br>
}<br>
<br>
Console.ReadLine();<br>
<br>
<u>Output:</u><br>
Doe a deer<br>
&nbsp; - John Doe (jdoe)<br>
Billy dilly<br>
&nbsp; - Billy Bob (bbob)<br>
<br></p>]]></description>
		<link>http://channel9.msdn.com/Forums/Coffeehouse/465305-API-Calls-and-XML-Objects-with-C/16b326e0fd61454dbaa79deb00d78482#16b326e0fd61454dbaa79deb00d78482</link>
		<pubDate>Thu, 16 Apr 2009 04:03:03 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/Coffeehouse/465305-API-Calls-and-XML-Objects-with-C/16b326e0fd61454dbaa79deb00d78482#16b326e0fd61454dbaa79deb00d78482</guid>
		<dc:creator>ktr</dc:creator>
		<slash:comments>12</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ktr/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Coffeehouse - C# Anonymous Type Enhancement</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">stun said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">littleguru said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
This is a cool piece of code...I like it.
<div>I haven't had a chance to watch those videos about C# 4.0 and something about dynamic language features...</div>
<div><br>
</div>
<div>I don't even have a clue about what they mean by &quot;dynamic&quot; yet.</div>
<div>Anyone who can explain it to me very quickly about what those new dynamic language features are in C# 4.0?</div>
</div></blockquote>Sure, basically as of C# 3, everything was statically typed, meaning the compiler knows the type of everything at compile time. This is good because it gives you a safety net when passing different types around; since the compiler knows what properties/methods
 accept as parameters and return as values it can ensure you are passing the right types.<br>
<br>
However, sometimes you have no idea what the type of the thing is. A good example is XML. Most of the time the XML is loosely typed and we have to resort to element.Element(&quot;FirstName&quot;).Value. Other good examples of things that do not have static type information
 are: REST services, COM APIs, the HTML DOM, SQL Result Sets (When not using ORM). Also when communicating with a library written in alanguage that does not have static typing (Ruby, Python, JScript, ...)<br>
<br>
So it makes sense to have a concept of dynamic in the language for these things that do not have static types. C# introduces this in the form of IDynamicObject. If you implement this interface on a class, that means that you can intercept all calls to the object
 for method calls, property setters/getters, etc and define logic for them.<br>
<br>
Then we could deal with XML in a more natural way:<br>
// xmlElement is statically typed as dynamic<br>
string firstName = xmlElement.FirstName;<br>
<br>
Or REST Services:<br>
// restEndpoint is statically typed as dynamic<br>
List&lt;People&gt; = restEndpoint.People.Group(&quot;Marketing&quot;);<br>
<br>
Or SQL Result sets:<br>
// db.Query() returns an IEnumerable of dynamic objects (objects that implement IDynamicObject)<br>
foreach (dynamic person in db.Query(&quot;SELECT * FROM People&quot;)) {<br>
&nbsp; Console.WriteLine(person.FirstName);<br>
&nbsp; Console.WriteLine(person.LastName);<br>
&nbsp; // ...<br>
}<br>
<br>
You should read here for more information: <br>
<a target="_blank" href="http://blogs.microsoft.co.il/blogs/shayf/archive/2008/12/19/the-dynamic-keyword-part-1-introduction.aspx">http://blogs.microsoft.co.il/blogs/shayf/archive/2008/12/19/the-dynamic-keyword-part-1-introduction.aspx</a><br>
<a target="_blank" href="http://blogs.msdn.com/samng/archive/2008/10/29/dynamic-in-c.aspx">http://blogs.msdn.com/samng/archive/2008/10/29/dynamic-in-c.aspx</a><br></p>]]></description>
		<link>http://channel9.msdn.com/Forums/Coffeehouse/461467-C-Anonymous-Type-Enhancement/e51ef285b3d74626b42f9deb00d1c459#e51ef285b3d74626b42f9deb00d1c459</link>
		<pubDate>Thu, 19 Mar 2009 19:47:09 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/Coffeehouse/461467-C-Anonymous-Type-Enhancement/e51ef285b3d74626b42f9deb00d1c459#e51ef285b3d74626b42f9deb00d1c459</guid>
		<dc:creator>ktr</dc:creator>
		<slash:comments>8</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ktr/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Coffeehouse - C# Anonymous Type Enhancement</title>
		<description><![CDATA[<p><div><br>
</div>
I like that idea a lot; very cool. &nbsp;I would prefer a syntax like this though:
<div><br>
</div>
<div>var employee = new IEmployee { EmployeeId = 1, FirstName = &quot;John&quot;, LastName = &quot;Doe&quot; };</div>
<div><br>
</div>
<div>for interfaces, the compiler would automatically create a class that implements that interface unless it is impossible (i.e. if it has methods -- currently not supported in anonymous types).</div></p>]]></description>
		<link>http://channel9.msdn.com/Forums/Coffeehouse/461467-C-Anonymous-Type-Enhancement/d3905ab31c514e87835a9deb00d1c230#d3905ab31c514e87835a9deb00d1c230</link>
		<pubDate>Wed, 18 Mar 2009 21:18:29 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/Coffeehouse/461467-C-Anonymous-Type-Enhancement/d3905ab31c514e87835a9deb00d1c230#d3905ab31c514e87835a9deb00d1c230</guid>
		<dc:creator>ktr</dc:creator>
		<slash:comments>8</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ktr/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - switch (object.GetType) ...</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">littleguru said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">TommyCarlier said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
That's some kind of a nice implementation, very object oriented, awesome... but what about running it multiple times without having to re-create the instance over and over again...</div></blockquote>How about a switch method that re-initializes the object and its type
 internally? That way you define an instance at the highest scope possible and reuse it. I ran a rough test to compare the speeds of casting normally vs. using a type-switcher with the type-switcher declared outside&nbsp; all loops. Modified the code yet again.
 Props to Tommy for that OOP goodness.<br /><br />I'm not sure if DateTime and TimeSpan measurements are very accurate, but that's what I used.<br /><br />100 iterations: Type Switcher: 15ms / Normal Cast: 15ms<br />1,000 iterations: Type Switcher: 78ms / Normal Cast: 62ms<br />10,000 iterations: Type Switcher: 640ms / Normal Cast: 576ms<br />100,000 iterations: Type Switcher: 5984ms / Normal Cast: 5781ms<br /><br />Code:<br /><br />class Program<br />{<br />&nbsp; static TypeSwitcher typeSwitcher = new TypeSwitcher();<br /><br />&nbsp; static void Main(string[] args) {<br /><br />&nbsp;&nbsp;&nbsp; TimeSpan testTypeSwitcherSpan;<br />&nbsp;&nbsp;&nbsp; DateTime testTypeSwitcherStart = DateTime.Now;<br />&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; 100000; i&#43;&#43;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TestTypeSwitcher();<br />&nbsp;&nbsp;&nbsp; testTypeSwitcherSpan = DateTime.Now - testTypeSwitcherStart;<br /><br />&nbsp;&nbsp;&nbsp; TimeSpan testTypeCastSpan;<br />&nbsp;&nbsp;&nbsp; DateTime testTypeCastStart = DateTime.Now;<br />&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; 100000; i&#43;&#43;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TestTypeCast();<br />&nbsp;&nbsp;&nbsp; testTypeCastSpan = DateTime.Now - testTypeCastStart;<br /><br />&nbsp;&nbsp;&nbsp; Console.WriteLine(&quot;Type Switcher Object: {0}&quot;, testTypeSwitcherSpan.TotalMilliseconds);<br />&nbsp;&nbsp;&nbsp; Console.WriteLine(&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Type Cast: {0}&quot;, testTypeCastSpan.TotalMilliseconds);<br /><br />&nbsp;&nbsp;&nbsp; Console.ReadLine();<br />&nbsp; }<br /><br />&nbsp; static void TestTypeSwitcher() {<br />&nbsp;&nbsp;&nbsp; object obj = null;<br /><br />&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; 3; i&#43;&#43;) {<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; switch (i) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 0: obj = &quot;Hello World&quot;; break;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 1: obj = 32; break;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 2: obj = DateTime.Now; break;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; typeSwitcher.Switch(obj)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .Case&lt;string&gt;(x =&gt; Console.Write(&quot;.&quot;))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .Case&lt;int&gt;(x =&gt; Console.Write(&quot;.&quot;))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .Case&lt;DateTime&gt;(x =&gt; Console.Write(&quot;.&quot;));<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp; }<br /><br />&nbsp; static void TestTypeCast() {<br />&nbsp;&nbsp;&nbsp; object obj = null;<br /><br />&nbsp;&nbsp;&nbsp; var typeSwitcher = new TypeSwitcher();<br /><br />&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; 3; i&#43;&#43;) {<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; switch (i) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 0: obj = &quot;Hello World&quot;; break;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 1: obj = 32; break;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 2: obj = DateTime.Now; break;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string x1 = obj as string;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (x1 != null) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.Write(&quot;.&quot;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else if (obj is int) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int x2 = (int)obj;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.Write(&quot;.&quot;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else if (obj is DateTime) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DateTime x3 = (DateTime)obj;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.Write(&quot;.&quot;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp; }<br />}<br /><br />public class TypeSwitcher<br />{<br />&nbsp; private object obj;<br />&nbsp; private Type type;<br /><br />&nbsp; public TypeSwitcher() { }<br /><br />&nbsp; public TypeSwitcher Switch(object o) {<br />&nbsp;&nbsp;&nbsp; obj = o;<br />&nbsp;&nbsp;&nbsp; type = o.GetType();<br />&nbsp;&nbsp;&nbsp; return this;<br />&nbsp; }<br /><br />&nbsp; public TypeSwitcher Case&lt;T&gt;(Action&lt;T&gt; handler) {<br />&nbsp;&nbsp;&nbsp; Type t = typeof(T);<br />&nbsp;&nbsp;&nbsp; if (!IsMatch(t)) return this;<br /><br />&nbsp;&nbsp;&nbsp; handler((T)obj);<br />&nbsp;&nbsp;&nbsp; return IgnoreTypeSwitcher.Instance;<br />&nbsp; }<br /><br />&nbsp; protected virtual bool IsMatch(Type t) {<br />&nbsp;&nbsp;&nbsp; if (obj == null)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw new Exception(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;TypeSwitcher cannot switch on a null reference. &quot; &#43;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;Make sure to call Switch before Case.&quot;);<br /><br />&nbsp;&nbsp;&nbsp; return t.Equals(type);<br />&nbsp; }<br /><br />&nbsp; class IgnoreTypeSwitcher : TypeSwitcher<br />&nbsp; {<br />&nbsp;&nbsp;&nbsp; IgnoreTypeSwitcher() : base() { }<br />&nbsp;&nbsp;&nbsp; public static IgnoreTypeSwitcher Instance = new IgnoreTypeSwitcher();<br />&nbsp;&nbsp;&nbsp; protected override bool IsMatch(Type t) { return false; }<br />&nbsp; }<br />}<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/411739-switch-objectGetType-/b31e3a289def4dbd94839dfa0092a938#b31e3a289def4dbd94839dfa0092a938</link>
		<pubDate>Thu, 26 Jun 2008 09:47:53 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/411739-switch-objectGetType-/b31e3a289def4dbd94839dfa0092a938#b31e3a289def4dbd94839dfa0092a938</guid>
		<dc:creator>ktr</dc:creator>
		<slash:comments>50</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ktr/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - switch (object.GetType) ...</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">TommyCarlier said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">littleguru said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>I was too fast <img src="http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-6.gif" alt="Sad"></p>
<p>I read over the constructor that stores the type of the object. I should just acknowledge I'm getting too old, and that young geniuses like LG can make me look stupid
<img src="http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-5.gif" alt="Wink"></p>
</div></blockquote>Hahaha, Tommy that's awesome. I was just about to post the <b>exact</b> same thing. Great minds think alike I hear.<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/411739-switch-objectGetType-/04dceebdb83d43fa8cb69dfa0092a54b#04dceebdb83d43fa8cb69dfa0092a54b</link>
		<pubDate>Thu, 26 Jun 2008 06:58:07 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/411739-switch-objectGetType-/04dceebdb83d43fa8cb69dfa0092a54b#04dceebdb83d43fa8cb69dfa0092a54b</guid>
		<dc:creator>ktr</dc:creator>
		<slash:comments>50</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ktr/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - switch (object.GetType) ...</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">littleguru said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">TommyCarlier said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
But: he already extracts the type from the object that's passed in the constructor. Why not use that information and only store the handler that is intended for that type? I mean why storing all the handlers in the dictionary; that doesn't make any sense to
 me. I mean in the end he's again using the type information to get the appropriate handler and there's no way to change the object that's passed into the constructor after the &quot;Switcher&quot; has been created.<br /><br />I wouldn't use a hashtable here because it's complete overkill and makes the whole thing slow... We can argue on this when you use some kind of inheritance chain to apply multiple handlers when some are registered for the base classes of the type etc... but
 in this scenario here, dunno.</div></blockquote>You're absolutely right. it is overkill, but I thought it would be fun =). Thanks for the tip, Tommy, I did not know that. Anyway here is a slightly more efficient version. This way you could reuse the type-switcher in
 other parts of your program and just call .Switch(object) when you want to perform an action corresponding to the type.<br /><br /><b>public static void </b>Main(<b>string</b>[] args) {<br /><br />&nbsp;&nbsp;&nbsp; <b>object </b>obj = <b>null</b>;<br />&nbsp;&nbsp;&nbsp; obj = &quot;Hello World&quot;;<br />&nbsp;&nbsp;&nbsp; //obj = 32;<br />&nbsp;&nbsp;&nbsp; //obj = DateTime.Now;<br /><br />&nbsp;&nbsp;&nbsp; <b>new </b>TypeSwitcher()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .Case&lt;<b>string</b>&gt;(x =&gt; Console.WriteLine(&quot;string: {0}&quot;, x))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .Case&lt;<b>int</b>&gt;(x =&gt; Console.WriteLine(&quot;int: {0}&quot;, x))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .Case&lt;<b>DateTime</b>&gt;(x =&gt; Console.WriteLine(&quot;DateTime: {0}&quot;, x))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .Switch(obj);<br /><br />&nbsp;&nbsp;&nbsp; Console.ReadLine();<br />}<br /><br />// ...<br /><br /><b>public class </b>TypeSwitcher<br />&nbsp; {<br />&nbsp;&nbsp;&nbsp; <b>private readonly </b>Dictionary&lt;Type, Action&lt;<b>object</b>&gt;&gt; handlers =<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b>new </b>Dictionary&lt;Type, Action&lt;<b>object</b>&gt;&gt;();<br /><br />&nbsp;&nbsp;&nbsp; <b>public </b>TypeSwitcher() { }<br /><br />&nbsp;&nbsp;&nbsp; <b>public </b>TypeSwitcher Case&lt;T&gt;(Action&lt;T&gt; handler) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Type t = <b>typeof</b>(T);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Action&lt;<b>object</b>&gt; boxedHandler = o =&gt; handler((T)o);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; handlers[t] = boxedHandler;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b>return this</b>;<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; <b>public void </b>Switch(<b>object </b>o) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Type t = o.GetType();<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Action&lt;<b>object</b>&gt; handler;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b>if </b>(handlers.TryGetValue(t, <b>out </b>handler))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; handler(o);<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp; }<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/411739-switch-objectGetType-/0dc5a0648f5a44fcabe89dfa0092a42a#0dc5a0648f5a44fcabe89dfa0092a42a</link>
		<pubDate>Thu, 26 Jun 2008 06:39:55 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/411739-switch-objectGetType-/0dc5a0648f5a44fcabe89dfa0092a42a#0dc5a0648f5a44fcabe89dfa0092a42a</guid>
		<dc:creator>ktr</dc:creator>
		<slash:comments>50</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ktr/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - switch (object.GetType) ...</title>
		<description><![CDATA[<p>A little bit of fun... yes, I know it's horribly inefficient =) <br /><br /><div><b>public static void </b>Main(<b>string</b>[] args) {<br /><br />&nbsp;&nbsp; <b>object </b>obj = null;<br />&nbsp;&nbsp; <br />&nbsp;&nbsp; obj = &quot;Hello World&quot;;<br />&nbsp;&nbsp; // obj = 32;<br />&nbsp;&nbsp; // obj = DateTime.Now;<br />&nbsp;&nbsp; // uncomment the above lines to see a different output<br /><br />&nbsp;&nbsp; TypeSwitcher.Switch(obj)<br />&nbsp; &nbsp; .Case&lt;<b>string</b>&gt;(x =&gt; Console.WriteLine(&quot;string: {0}&quot;, x))<br />&nbsp; &nbsp; .Case&lt;<b>int</b>&gt;(x =&gt; Console.WriteLine(&quot;int: {0}&quot;, x))<br />&nbsp; &nbsp; .Case&lt;<b>DateTime</b>&gt;(x =&gt; Console.WriteLine(&quot;DateTime: {0}&quot;, x))<br />&nbsp; &nbsp; .Execute();<br />}<br /><br />//...<br /><br /><b>public class </b>TypeSwitcher<br />{<br />&nbsp;&nbsp;&nbsp; <b>private readonly object </b>obj;<br />&nbsp;&nbsp;&nbsp; <b>private readonly </b>Type type;<br />&nbsp;&nbsp;&nbsp; <b>private readonly </b>Dictionary&lt;Type, Action&lt;<b>object</b>&gt;&gt; handlers =<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b>new </b>Dictionary&lt;Type, Action&lt;<b>object</b>&gt;&gt;();<br /><br />&nbsp;&nbsp;&nbsp; <b>private </b>TypeSwitcher(<b>object </b>o) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; obj = o;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; type = o.GetType();<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; <b>public </b>TypeSwitcher Case&lt;T&gt;(Action&lt;T&gt; handler) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Type t = <b>typeof</b>(T);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Action&lt;<b>object</b>&gt; boxedHandler = o =&gt; handler((T)o);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b>if </b>(!handlers.ContainsKey(t))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; handlers.Add(t, boxedHandler);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b>else</b><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; handlers[t] = boxedHandler;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b>return this</b>;<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; <b>public void </b>Execute() {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Action&lt;<b>object</b>&gt; handler;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b>if </b>(handlers.TryGetValue(type, <b>out </b>handler))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; handler(obj);<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; <b>public static </b>TypeSwitcher Switch(<b>object </b>o) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b>return new </b>TypeSwitcher(o);<br />&nbsp;&nbsp;&nbsp; }<br />}<br /></div></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/411739-switch-objectGetType-/1d020441742f4c3399589dfa0092a2bb#1d020441742f4c3399589dfa0092a2bb</link>
		<pubDate>Thu, 26 Jun 2008 05:49:01 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/411739-switch-objectGetType-/1d020441742f4c3399589dfa0092a2bb#1d020441742f4c3399589dfa0092a2bb</guid>
		<dc:creator>ktr</dc:creator>
		<slash:comments>50</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ktr/Discussions/RSS</wfw:commentRss>
	</item>
</channel>
</rss>