Created
August 17, 2013 14:50
-
-
Save robinvanderknaap/6257250 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
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