Created
October 8, 2018 01:44
-
-
Save abc126/0f7e8b049fd61954a971acd09fa64d8c to your computer and use it in GitHub Desktop.
PresenterBindingAttribute
This file contains hidden or 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
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| namespace MVP | |
| { | |
| [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] | |
| public sealed class PresenterBindingAttribute : Attribute | |
| { | |
| public Type PresenterType { get; private set; } | |
| public PresenterBindingAttribute(Type presenterType) | |
| { | |
| PresenterType = presenterType; | |
| } | |
| } | |
| public static class ViewExtension | |
| { | |
| public static object BindingPresenter(this ViewWithPresenterBase viewInstance) | |
| { | |
| object presenter = null; | |
| Type t = viewInstance.GetType(); | |
| object[] attrs = t.GetCustomAttributes(typeof(PresenterBindingAttribute), false); | |
| foreach (PresenterBindingAttribute pba in attrs) | |
| { | |
| Type newt = pba.PresenterType; | |
| presenter = Activator.CreateInstance(pba.PresenterType, viewInstance); | |
| } | |
| return presenter; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment