Created
April 22, 2010 19:37
-
-
Save thomasjo/375704 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // Pretend this is a LINQ to SQL entity | |
| public class Product | |
| { | |
| public string Name { get; private set; } | |
| public IEnumerable<ProductTranslation> Translations { get; private set; } | |
| public Product(string name, IEnumerable<ProductTranslation> translations) | |
| { | |
| Name = name; | |
| Translations = translations; | |
| } | |
| } |
This file contains hidden or 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
| // Pretend this is a LINQ to SQL entity | |
| public class ProductTranslation | |
| { | |
| public string Name { get; set; } | |
| public ProductTranslation(string name) | |
| { | |
| Name = name; | |
| } | |
| } |
This file contains hidden or 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
| public static class Translator | |
| { | |
| public static dynamic Translate(dynamic original, Func<dynamic, dynamic> expression) | |
| { | |
| var translation = Enumerable.FirstOrDefault(original.Translations); | |
| if (translation == null) { | |
| return expression.Invoke(original); | |
| } | |
| return expression.Invoke(translation); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment