本文整理汇总了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;
}
}
示例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));
}
示例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);
}
}
示例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;
}
}
示例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 });
}
}
}