//****************************************

        private IDictionary <Type, IDictionary <string, GuiCommandTemplate> > LoadCommands()
        {               //****************************************
            Dictionary <Type, IDictionary <string, GuiCommandTemplate> > MyPresenters;
            Dictionary <string, GuiCommandTemplate> MyCommandTemplates;

            object[]           MyAttributes;
            GuiCommandTemplate MyTemplate;

            //****************************************

            MyPresenters = new Dictionary <Type, IDictionary <string, GuiCommandTemplate> >();

            foreach (Type MyType in _PrimaryAssembly.GetTypes())
            {
                if (MyType.IsAbstract || !MyType.IsClass)
                {
                    continue;
                }

                if (!typeof(GuiPresenter).IsAssignableFrom(MyType))
                {
                    continue;
                }

                //****************************************

                MyCommandTemplates = new Dictionary <string, GuiCommandTemplate>();

                foreach (MethodInfo MyMethod in MyType.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
                {
                    if (MyMethod.ReturnType != typeof(void) || MyMethod.GetParameters().Length != 0)
                    {
                        continue;
                    }

                    MyAttributes = MyMethod.GetCustomAttributes(typeof(GuiCommandAttribute), true);

                    if (MyAttributes.Length == 0)
                    {
                        continue;
                    }

                    MyTemplate = new GuiCommandTemplate(MyType, MyMethod, (GuiCommandAttribute)MyAttributes[0]);

                    MyCommandTemplates.Add(MyTemplate.Name, MyTemplate);
                }

                //****************************************

                MyPresenters.Add(MyType, MyCommandTemplates);
            }


            //****************************************

            return(MyPresenters);
        }
예제 #2
0
        //****************************************

        private void OnCanExecuteRoutedEvent(object sender, CanExecuteRoutedEventArgs e)
        {               //****************************************
            GuiCommandTemplate MyTemplate = Presenter.Host.GetCommandTemplate(Presenter, ((WpfCommand)e.Command).TemplateName);

            //****************************************

            // We received a Command, check if our Presenter can handle it
            e.CanExecute = MyTemplate.CanCheckExecute ? MyTemplate.CheckExecute(Presenter) : false;
        }