Skip to content

Instantly share code, notes, and snippets.

@pavel-drabushevich
Created May 12, 2011 11:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pavel-drabushevich/968328 to your computer and use it in GitHub Desktop.
Save pavel-drabushevich/968328 to your computer and use it in GitHub Desktop.
Мир верх тормашками или код как данные
using System;
namespace CodeAsData
{
public class Pair
{
static void Main(string[] args)
{
var pair = create(1, 'a');
Console.WriteLine(key(pair) + ":" + value(pair));
}
public static Func<Operation, object> create(object key, object value)
{
return delegate(Operation operation)
{
if (operation == Operation.Key)
return key;
else if (operation == Operation.Value)
return value;
else
throw new Exception("WTF?!");
};
}
public static object key(Func<Operation, object> pair)
{
return pair(Operation.Key);
}
public static object value(Func<Operation, object> pair)
{
return pair(Operation.Value);
}
public enum Operation
{
Key, Value
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment