当前位置: 首页>>代码示例>>C#>>正文


C# IPresenter.GetType方法代码示例

本文整理汇总了C#中IPresenter.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IPresenter.GetType方法的具体用法?C# IPresenter.GetType怎么用?C# IPresenter.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IPresenter的用法示例。


在下文中一共展示了IPresenter.GetType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Bind

        public void Bind(IPresenter presenter)
        {
            var presenterType = presenter.GetType();
            var menu = BindingHelper.GetViewControls(presenter.View).OfType<MenuStrip>().FirstOrDefault();
            if (menu == null)
                return;

            var items = GetMenuItems(menu);

            var presenterMethods = BindingHelper.GetParameterlessActionMethods(presenterType);

            foreach (var method in presenterMethods)
            {
                string methodName = method.Name;
                var item = items.FirstOrDefault(
                    x => x.Name == Convensions.MenuItemPrefix + methodName.Substring(Convensions.EventHandlerPrefix.Length));

                if (item == null)
                    continue;

                var action = (Action)Delegate.CreateDelegate(typeof(Action), presenter, method.Name);

                var handler = (EventHandler)((sender, args) => action());
                item.Click += handler;
            }
        }
开发者ID:nyxiscoo1,项目名称:DipDemo,代码行数:26,代码来源:MenuClickEventBinder.cs

示例2: Bind

        public void Bind(IPresenter presenter)
        {
            if(!(presenter.View is Form))
                return;

            Type presenterType = presenter.GetType();
            var method = BindingHelper.GetActionMethods(presenterType)
                .SingleOrDefault(x => x.GetParameters().Length == 1
                                      && x.GetParameters()[0].ParameterType == typeof (IViewClosingEventData));

            if(method == null)
                return;

            var view = presenter.View as Form;
            var action = Delegate.CreateDelegate(typeof(Action<>).MakeGenericType(typeof (IViewClosingEventData)),
                                                     presenter, method);

            view.FormClosing += (o, e) => action.DynamicInvoke(new WinFormClosingEventData(e));
        }
开发者ID:nyxiscoo1,项目名称:DipDemo,代码行数:19,代码来源:ViewClosingEventBinder.cs

示例3: Bind

        public void Bind(IPresenter presenter)
        {
            var presenterType = presenter.GetType();
            var controls = BindingHelper.GetViewControls(presenter.View).OfType<Button>();

            var facts = presenterType.GetProperties()
                .Where(x =>
                       x.PropertyType == typeof(Fact)
                       && x.Name.StartsWith(Convensions.EnablinessPropertyPrefix));

            foreach (var fact in facts)
            {
                string factName = fact.Name;
                var btn = controls.FirstOrDefault(x => factName.EndsWith(x.Name.Substring(Convensions.ButtonPrefix.Length)));
                if (btn == null)
                    continue;

                Fact factInst = (Fact)fact.GetValue(presenter, null);
                new EnableControlCommand(btn, factInst);
            }
        }
开发者ID:nyxiscoo1,项目名称:DipDemo,代码行数:21,代码来源:ButtonEnablinessBinder.cs

示例4: Bind

        public void Bind(IPresenter presenter)
        {
            var presenterType = presenter.GetType();
            var controls = BindingHelper.GetViewControls(presenter.View).OfType<Button>();

            var presenterMethods = BindingHelper.GetParameterlessActionMethods(presenterType);

            foreach (var method in presenterMethods)
            {
                string methodName = method.Name;
                var btn = controls.FirstOrDefault(
                    x => x.Name == Convensions.ButtonPrefix + methodName.Substring(Convensions.EventHandlerPrefix.Length));

                if (btn == null)
                    continue;

                var action = (Action)Delegate.CreateDelegate(typeof(Action), presenter, method.Name);

                var handler = (EventHandler)((sender, args) => action());
                btn.Click += handler;
            }
        }
开发者ID:nyxiscoo1,项目名称:DipDemo,代码行数:22,代码来源:ButtonClickEventBinder.cs

示例5: Init

 public void Init(IPresenter module)
 {
     var type = module.GetType();
     foreach (var p in type.GetProperties())
     {
         var cmd = Attribute.GetCustomAttribute(p, typeof(RelayCommandAttribute), false) as RelayCommandAttribute;
         if (cmd != null)
         {
             var name = cmd.Name ?? p.Name;
             var c = p.GetValue(module, null) as ICommand;
             if (!Commands.ContainsName(name))
                 Register(new RelayCommandModel { Name = name, Command = c });
         }
         var e = Attribute.GetCustomAttribute(p, typeof(EventCommandAttribute), false) as EventCommandAttribute;
         if (e != null)
         {
             var name = e.Name ?? p.Name;
             var c = p.GetValue(module, null) as ICommand;
             if (!Commands.ContainsName(name))
                 Register(new EventCommandModel { Name = name, EventName = e.EventName, Command = c });
         }
     }
 }
开发者ID:eolandezhang,项目名称:Diagram,代码行数:23,代码来源:CommandContext.cs


注:本文中的IPresenter.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。