Skip to content

Instantly share code, notes, and snippets.

@robinvanderknaap
Created August 17, 2013 14:50
Show Gist options
  • Save robinvanderknaap/6257250 to your computer and use it in GitHub Desktop.
Save robinvanderknaap/6257250 to your computer and use it in GitHub Desktop.
public class ViewBaseClass<TModel> : DefaultTemplateBase<TModel>
{
private readonly ITranslationService _translationService;
private CultureInfo _culture;
public ViewBaseClass(ITranslationService translationService, IApplicationSettings applicationSettings)
{
_translationService = translationService;
ApplicationSettings = applicationSettings;
}
public IApplicationSettings ApplicationSettings { get; private set; }
public CultureInfo Culture
{
get { return _culture ?? ApplicationSettings.DefaultCulture; }
set { _culture = value; }
}
public dynamic T
{
get { return new DynamicTranslationService(_translationService, _culture); }
}
private class DynamicTranslationService : DynamicObject
{
private readonly ITranslationService _translationService;
private readonly CultureInfo _culture;
public DynamicTranslationService(ITranslationService translationService, CultureInfo culture)
{
_translationService = translationService;
_culture = culture;
}
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
result = _translationService.Translate(binder.Name, _culture);
return true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment