﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Ayende Rahien commented on Code of the week</title><description>Dmitry,
  
In this case, what I wanted was no reflection. The price paid for it is worth it, I think.
</description><link>http://ayende.com/3355/code-of-the-week#comment12</link><guid>http://ayende.com/3355/code-of-the-week#comment12</guid><pubDate>Fri, 13 Jun 2008 10:21:21 GMT</pubDate></item><item><title>Dmitry Gusarov commented on Code of the week</title><description>Ok, but Andrey suggested an excellent duplication removal.
  
I thought of it... what is more valuable? Avoiding reflection or avoiding duplication... In any case we have a tests ;)
</description><link>http://ayende.com/3355/code-of-the-week#comment11</link><guid>http://ayende.com/3355/code-of-the-week#comment11</guid><pubDate>Fri, 13 Jun 2008 07:28:22 GMT</pubDate></item><item><title>Ayende Rahien commented on Code of the week</title><description>That involves reflection. I wanted this to be zero reflection effort
</description><link>http://ayende.com/3355/code-of-the-week#comment10</link><guid>http://ayende.com/3355/code-of-the-week#comment10</guid><pubDate>Sun, 08 Jun 2008 09:42:59 GMT</pubDate></item><item><title>Andrey Shchekin commented on Code of the week</title><description>What about 
  
IDictionary&lt;string, Func&lt;Stream, ICommand&gt;&gt; CreateCommandFactories(IEnumerable&lt;Type&gt; types) {
  
      return (
  
            from type in types
  
            select new {
  
                  Name = type.Name.Replace("Command", "").ToLowerInvariant(),
  
                  Factory = (Func&lt;Stream, ICommand&gt;)(s =&gt; Activator.CreateInstance(type, s))
  
            }
  
      ).ToDictionary(
  
            x =&gt; x.Name,
  
            x =&gt; x.Factory
  
      )
  
}
  
  
Of course better way would be to use Regex for parsing and Expression.Compile for constructor. 
</description><link>http://ayende.com/3355/code-of-the-week#comment9</link><guid>http://ayende.com/3355/code-of-the-week#comment9</guid><pubDate>Sun, 08 Jun 2008 08:58:07 GMT</pubDate></item><item><title>Ayende Rahien commented on Code of the week</title><description>I like using the most abstract type possible
</description><link>http://ayende.com/3355/code-of-the-week#comment8</link><guid>http://ayende.com/3355/code-of-the-week#comment8</guid><pubDate>Sat, 07 Jun 2008 05:15:07 GMT</pubDate></item><item><title>firefly commented on Code of the week</title><description>Question...
  
private static IDictionary do you gain anything by using the IDictionary interface verse just using a regular Dictionary class?
</description><link>http://ayende.com/3355/code-of-the-week#comment7</link><guid>http://ayende.com/3355/code-of-the-week#comment7</guid><pubDate>Sat, 07 Jun 2008 04:50:43 GMT</pubDate></item><item><title>firefly commented on Code of the week</title><description>The more I dig into C# 3.0 the more I infatuate with it.
</description><link>http://ayende.com/3355/code-of-the-week#comment6</link><guid>http://ayende.com/3355/code-of-the-week#comment6</guid><pubDate>Fri, 06 Jun 2008 21:29:31 GMT</pubDate></item><item><title>Vijay Santhanam commented on Code of the week</title><description>love the dictionary lookups with the generic delegates/lambdas too.
  
  
as much as i'm interested in your code, i'm doubley interested in your design process. e.g., how much analyse/OO modelling you do before you start writing real code?
  
  
With tools like R#/svn is the up-front design pretty much dead for garage projects?
  
  
would like to read about the steps you take before you get to code. i ask because as a sophisicated practitioner, you take intermediate working steps for granted whilst someone at my level struggles to keep up sometimes.
</description><link>http://ayende.com/3355/code-of-the-week#comment5</link><guid>http://ayende.com/3355/code-of-the-week#comment5</guid><pubDate>Fri, 06 Jun 2008 17:29:53 GMT</pubDate></item><item><title>Harry M commented on Code of the week</title><description>Have I just made a DSL?
  
  
public static void Main(string[] args)
  
		{
  
			var me = new Person("Harry");
  
			var you = new Person("Bob");
  
			var options = new Dictionary&lt;string, Action&lt;string&gt;&gt;()
  
			              {
  
			              	{"I", s =&gt; DoSomething(me, s)},
  
							{"You", s =&gt; DoSomething(you, s)}
  
			              };
  
			Parse("I say hello", options);
  
			Parse("I jump", options);
  
			Parse("You say goodbye", options);
  
  
		}
  
  
		private static void Parse(string command, IDictionary&lt;string, Action&lt;string&gt;&gt; options)
  
		{
  
			string[] parts = command.Split(new char[] {' '}, 2);
  
			options[parts[0]](parts.Length &gt; 1 ? parts[1] : null);
  
		}
  
  
		private static void DoSomething(Person who, string what)
  
		{
  
			var options = new Dictionary&lt;string, Action&lt;string&gt;&gt;()
  
			              {
  
			              	{"say", s =&gt; who.Say(s)},
  
			              	{"jump", s =&gt; who.Jump()}
  
			              };
  
			Parse(what, options);
  
		}
  
		class Person
  
		{
  
			private readonly string name;
  
			public Person(string name)
  
			{
  
				this.name = name;
  
			}
  
			public void Say(string message)
  
			{
  
				Console.WriteLine("{0} says: '{1}'", name, message);
  
			}
  
			public void Jump()
  
			{
  
				Console.WriteLine("{0} jumps", name);
  
			}
  
		}
</description><link>http://ayende.com/3355/code-of-the-week#comment4</link><guid>http://ayende.com/3355/code-of-the-week#comment4</guid><pubDate>Fri, 06 Jun 2008 13:27:54 GMT</pubDate></item><item><title>Gary A commented on Code of the week</title><description>So what does it do, and why did you do it this way?
</description><link>http://ayende.com/3355/code-of-the-week#comment3</link><guid>http://ayende.com/3355/code-of-the-week#comment3</guid><pubDate>Fri, 06 Jun 2008 13:20:28 GMT</pubDate></item><item><title>Alex Simkin commented on Code of the week</title><description>You should have request commands from IoC container, not from the dictionary.
  
</description><link>http://ayende.com/3355/code-of-the-week#comment2</link><guid>http://ayende.com/3355/code-of-the-week#comment2</guid><pubDate>Fri, 06 Jun 2008 13:18:57 GMT</pubDate></item><item><title>James L commented on Code of the week</title><description>They look like memcached commands
</description><link>http://ayende.com/3355/code-of-the-week#comment1</link><guid>http://ayende.com/3355/code-of-the-week#comment1</guid><pubDate>Fri, 06 Jun 2008 12:22:52 GMT</pubDate></item></channel></rss>