Skip to content

Instantly share code, notes, and snippets.

@thomasjo
Created April 22, 2010 19:37
Show Gist options
  • Select an option

  • Save thomasjo/375704 to your computer and use it in GitHub Desktop.

Select an option

Save thomasjo/375704 to your computer and use it in GitHub Desktop.
// 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;
}
}
// Pretend this is a LINQ to SQL entity
public class ProductTranslation
{
public string Name { get; set; }
public ProductTranslation(string name)
{
Name = name;
}
}
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