public static object GetParameterInstence(this Type type, string name, string injectionType = "")
        {
            if (injectionType == "")
            {
                if (type.IsPrimitive)
                {
                    return(Activator.CreateInstance(type));
                }
                else if (type == typeof(string))
                {
                    return("");
                }
                else
                {
                    return(FrameManager.CreateInstence(type));
                }
            }
            else
            {
                switch (injectionType)
                {
                case AppConst.Injection_Additional:
                    foreach (var tar in CreateInstenceState.GetBottomToTop())
                    {
                        if (tar is Dictionary <string, object> )
                        {
                            Dictionary <string, object> dic = tar as Dictionary <string, object>;
                            if (dic.ContainsKey(name))
                            {
                                return(dic[name]);
                            }
                        }
                    }
                    return(null);

                case AppConst.Injection_InternalData:
                    return(FrameManager.GetInstence <IGameData>().GetData(name));

                case AppConst.Injection_ExternalData:
                    return(FrameManager.GetData(name));

                case AppConst.Injection_NewInstence:
                    return(FrameManager.CreateInstence(type, "", name));

                case AppConst.Injection_NewGameObject:
                    return(FrameManager.GetNewGameObject(name));

                case AppConst.Injection_GameObject:
                    return(FrameManager.GetGameObject(name));

                default:
                    return(injectionType.ConvertToSimpleType(type));
                }
            }
        }
示例#2
0
        public void Initialization(object 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 (string.IsNullOrEmpty(attribute.UseCondition) || FrameManager.GetInstence <IGameData>().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(object initializedObject)
        {
            Type type = initializedObject.GetType();
            Initialization_RoutingNode_StackAttribute attribute = type.GetCustomAttribute(typeof(Initialization_RoutingNode_StackAttribute)) as Initialization_RoutingNode_StackAttribute;
            var IDPropertys = type.GetProperties().Where(p => p.IsDefined(typeof(RoutingIdentifyPropertyAttribute)));

            if (IDPropertys != null && IDPropertys.Count() > 0 && IDPropertys.First().GetValue(initializedObject) != null)
            {
                FrameManager.GetInstence <IStackRoutingController>(attribute.RoutingBlockID).AddNode(initializedObject, IDPropertys.First().GetValue(initializedObject));
            }
            else if (!attribute.IdentifyProperty.IsNullOrEmpty() & type.GetProperty(attribute.IdentifyProperty) != null && type.GetProperty(attribute.IdentifyProperty).GetValue(initializedObject) != null)
            {
                FrameManager.GetInstence <IStackRoutingController>(attribute.RoutingBlockID).AddNode(initializedObject, type.GetProperty(attribute.IdentifyProperty).GetValue(initializedObject));
            }
            else if (attribute.Identify != null)
            {
                FrameManager.GetInstence <IStackRoutingController>(attribute.RoutingBlockID).AddNode(initializedObject, attribute.Identify);
            }
        }