public static void PerformInitialization(this IInitializedObject initialized) { GetInitializer(AppConst.Init_Inject).Initialization(initialized); foreach (InitializationAttribute attribute in Attribute.GetCustomAttributes(initialized.GetType(), typeof(InitializationAttribute)).Where(p => (p as InitializationAttribute).InitializeTime == AppConst.InitMode_Before)) { GetInitializer(attribute.InitializeType).Initialization(initialized); } initialized.Initialization(); foreach (InitializationAttribute attribute in Attribute.GetCustomAttributes(initialized.GetType(), typeof(InitializationAttribute)).Where(p => (p as InitializationAttribute).InitializeTime == AppConst.InitMode_After)) { GetInitializer(attribute.InitializeType).Initialization(initialized); } }
public void Initialization(IInitializedObject initializedObject) { Type type = initializedObject.GetType(); foreach (PropertyInfo property in type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Where(p => p.IsDefined(typeof(InjectAttribute), true))) { foreach (InjectAttribute attribute in (InjectAttribute[])property.GetCustomAttributes(typeof(InjectAttribute), true)) { if (Basic.CheckConditions(attribute.UseCondition)) { if (string.IsNullOrEmpty(attribute.ParametersGetMode)) { property.SetValue(initializedObject, property.GetPropertyInstence()); } else { property.SetValue(initializedObject, property.GetPropertyInstence(attribute.ParametersGetMode)); } break; } } } foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Where(p => p.IsDefined(typeof(InjectAttribute), true))) { List <object> parametersList = new List <object>(); ParameterInfo[] parameters = method.GetParameters(); string ParametersGetMode = (method.GetCustomAttribute(typeof(InjectAttribute)) as InjectAttribute).ParametersGetMode; if (string.IsNullOrEmpty(ParametersGetMode)) { string[] ParametersGetModes = ParametersGetMode.Split(','); for (int i = 0; i < parameters.Length; i++) { parametersList.Add(parameters[i].GetParameterInstence(ParametersGetModes[i])); } } else { for (int i = 0; i < parameters.Length; i++) { parametersList.Add(parameters[i].GetParameterInstence()); } } method.Invoke(initializedObject, parametersList.ToArray()); } }
public void Initialization(IInitializedObject initializedObject) { INotifiedObject notifiedObject = initializedObject as INotifiedObject; notifiedObject.MsgHandlers = new Dictionary <string, IMsgHandler>(); foreach (MethodInfo method in notifiedObject.GetType().GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Where(p => p.IsDefined(typeof(MsgBindingAttribute), true))) { MsgBindingAttribute attribute = method.GetCustomAttribute(typeof(MsgBindingAttribute)) as MsgBindingAttribute; if (!notifiedObject.MsgHandlers.ContainsKey(attribute.TargetHandler)) { notifiedObject.MsgHandlers.Add(attribute.TargetHandler, Basic.Instence.GetInstence <IMsgHandler>("", attribute.TargetHandler)); } notifiedObject.MsgHandlers[attribute.TargetHandler].MsgEventHandlers.Add(attribute.MsgToken, Delegate.CreateDelegate(typeof(MsgEventHandler), method) as MsgEventHandler); Basic.Instence.GetSingleton <MsgManager>(AppConst.RootLevel, notifiedObject.MsgStstem).RegistMsg(notifiedObject, attribute.MsgToken); } }
public void Initialization(IInitializedObject initializedObject) { MonoBehaviour targetObject = (MonoBehaviour)initializedObject; foreach (GameObject g in targetObject.gameObject.GetInsideUI()) { IUINode uiNode = g.GetComponent <IUINode>(); if (uiNode != null) { UIBindingComponent[] components = g.GetComponents <UIBindingComponent>(); foreach (UIBehaviour ui in g.GetComponents <UIBehaviour>()) { UIBindingComponent[] targetBindingComponent = components.Where(p => p.targetComponent == ui.GetType().Name).ToArray(); if (targetBindingComponent.Length > 0) { GetBinder(ui.GetType().Name).Binding(ui, targetBindingComponent.First(), targetObject as IUILogicalNode); } } } } }
public void Initialization(IInitializedObject initializedObject) { Type type = initializedObject.GetType(); string propertyName = "Handlers"; Dictionary <string, EventHandler> tmpHandlers = new Dictionary <string, EventHandler>(); foreach (MethodInfo method in type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Where(p => p.IsDefined(typeof(HandlerEventBindingAttribute), true))) { HandlerEventBindingAttribute attribute = Attribute.GetCustomAttribute(method, typeof(HandlerEventBindingAttribute)) as HandlerEventBindingAttribute; string key = attribute.EventToken; if (!string.IsNullOrEmpty(attribute.TargetProperty)) { propertyName = attribute.TargetProperty; } tmpHandlers.Add(key, (EventHandler)Delegate.CreateDelegate(typeof(EventHandler), initializedObject, method)); } PropertyInfo property = type.GetProperty(propertyName); if (property != null) { property.SetValue(initializedObject, tmpHandlers); } }