-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Right now the expression to retrieve a translation property looks like this:
public static Expression<Func<StoreProduct, string>> ProductName
{
get
{
var cultureName = Thread.CurrentThread.CurrentCulture.Name;
var languageName = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;
return s => s.Product.Translations.FirstOrDefault(e => matchesCulture(cultureName).Invoke(e)).Name ??
s.Product.Translations.FirstOrDefault(e => matchesCulture(languageName).Invoke(e)).Name ??
s.Product.Translations.FirstOrDefault().Name;
}
}Right now we need to specify the property to retrieve (.Name) three times in this expression.
The end goal would be to split this expression into two expressions:
- One generic expression to determine the correct translation to use
- Another expression to retrieve te property from the single translation found with 1.
I'm thinking of something along the lines of this:
public static Expression<Func<Product, object>> FromTranslation
{
get
{
var cultureName = Thread.CurrentThread.CurrentCulture.Name;
var languageName = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;
Expression<Func<Product, ProductTranslation>> translationExpression = s =>
s.Translations.FirstOrDefault(t => t.Culture == cultureName) ??
s.Translations.FirstOrDefault(t => t.Culture == languageName) ??
s.Translations.FirstOrDefault();
Expression<Func<ProductTranslation, object>> memberExpression = t => t.Name;
// TODO: Combine expressions somehow?
throw new NotImplementedException();
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request