Created
May 12, 2011 11:07
-
-
Save pavel-drabushevich/968328 to your computer and use it in GitHub Desktop.
Мир верх тормашками или код как данные
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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