示例#1
0
        public LanguageController(IControllersProvider <T> controllersProvider, ILocalizer localizer)
            : base(controllersProvider, localizer)
        {
            var handlers = new List <IMessageHandler <T> >();

            foreach (MethodInfo methodInfo in GetType().GetMethods())
            {
                var attribute = Attribute.GetCustomAttribute(
                    methodInfo,
                    typeof(LanguageActionAttribute)
                    ) as LanguageActionAttribute;

                if (attribute is null)
                {
                    continue;
                }

                // ReSharper disable once UseNegatedPatternMatching
                var expression = GetType().GetProperty(attribute.ExpressionPropertyName)?.GetValue(this) as Expression;

                if (expression is null)
                {
                    throw new InvalidOperationException(
                              "Couldn't find expression property with name " + attribute.ExpressionPropertyName
                              );
                }

                handlers.Add(new LanguageActionHandler <T>(
                                 expression, localizer, methodInfo)
                             );
            }

            LanguageHandlers = handlers.ToArray();
        }
示例#2
0
 public ControllerMiddleware(IControllersProvider <T> controllersProvider, IGameCommunicator gameCommunicator,
                             ILocalizer localizer)
 {
     _controllersProvider = controllersProvider;
     _gameCommunicator    = gameCommunicator;
     _localizer           = localizer;
     _mainControllerName  = controllersProvider.MainControllerName;
 }
示例#3
0
 protected ActionController(IControllersProvider <T> controllersProvider, ILocalizer localizer)
     : base(controllersProvider, localizer)
 {
     ActionHandlers = (
         from methodInfo in GetType().GetMethods()
         let attribute = Attribute.GetCustomAttribute(methodInfo, typeof(ActionAttribute)) as ActionAttribute
                         where !(attribute is null)
                         select new ActionHandler <T>(attribute.LocalizationPath, localizer, methodInfo)
         )
                      .ToArray();
 }
示例#4
0
 protected ControllerBase(IControllersProvider <T> controllersProvider, ILocalizer localizer)
 {
     ControllersProvider = controllersProvider;
     Localizer           = localizer;
 }