Example #1
0
        /// <summary>
        /// Resolves the post constructors for the type.
        /// </summary>
        /// <returns>The post constructors.</returns>
        protected PostConstructorInfo[] ResolvePostConstructors(Type type)
        {
            var postConstructors = new List <PostConstructorInfo>();

            var methods = type.GetMethods(BindingFlags.FlattenHierarchy |
                                          BindingFlags.Public |
                                          BindingFlags.NonPublic |
                                          BindingFlags.Instance);

            for (int methodIndex = 0; methodIndex < methods.Length; methodIndex++)
            {
                var method = methods[methodIndex];

                var attributes = method.GetCustomAttributes(typeof(PostConstruct), true);
                if (attributes.Length > 0)
                {
                    var parameters = method.GetParameters();
                    var postConstructorParameters = new ParameterInfo[parameters.Length];
                    for (int paramIndex = 0; paramIndex < postConstructorParameters.Length; paramIndex++)
                    {
                        object identifier = null;
                        var    parameter  = parameters[paramIndex];

                        var parameterAttributes = parameter.GetCustomAttributes(typeof(Inject), true);
                        if (parameterAttributes.Length > 0)
                        {
                            identifier = (parameterAttributes[0] as Inject).identifier;
                        }

                        postConstructorParameters[paramIndex] = new ParameterInfo(parameter.ParameterType, identifier);
                    }

                    var postConstructor = new PostConstructorInfo(postConstructorParameters);

                    if (postConstructorParameters.Length == 0)
                    {
                        postConstructor.postConstructor = MethodUtils.CreateParameterlessMethod(type, method);
                    }
                    else
                    {
                        postConstructor.paramsPostConstructor = MethodUtils.CreateParameterizedMethod(type, method);
                    }

                    postConstructors.Add(postConstructor);
                }
            }

            return(postConstructors.ToArray());
        }
Example #2
0
        /// <summary>
        /// Resolves the post constructors for the type.
        /// </summary>
        /// <returns>The post constructors.</returns>
        protected PostConstructorInfo[] ResolvePostConstructors(Type type)
        {
            var postConstructors = new List<PostConstructorInfo>();

            var methods = type.GetMethods(BindingFlags.FlattenHierarchy |
                BindingFlags.Public |
                BindingFlags.NonPublic |
                BindingFlags.Instance);

            for (int methodIndex = 0; methodIndex < methods.Length; methodIndex++) {
                var method = methods[methodIndex];

                var attributes = method.GetCustomAttributes(typeof(PostConstruct), true);
                if (attributes.Length > 0) {
                    var parameters = method.GetParameters();
                    var postConstructorParameters = new ParameterInfo[parameters.Length];
                    for (int paramIndex = 0; paramIndex < postConstructorParameters.Length; paramIndex++) {
                        object identifier = null;
                        var parameter = parameters[paramIndex];

                        var parameterAttributes = parameter.GetCustomAttributes(typeof(Inject), true);
                        if (parameterAttributes.Length > 0) {
                            identifier = (parameterAttributes[0] as Inject).identifier;
                        }

                        postConstructorParameters[paramIndex] = new ParameterInfo(parameter.ParameterType, identifier);
                    }

                    var postConstructor = new PostConstructorInfo(postConstructorParameters);

                    if (postConstructorParameters.Length == 0) {
                        postConstructor.postConstructor = MethodUtils.CreateParameterlessMethod(type, method);
                    } else {
                        postConstructor.paramsPostConstructor = MethodUtils.CreateParameterizedMethod(type, method);
                    }

                    postConstructors.Add(postConstructor);
                }
            }

            return postConstructors.ToArray();
        }