コード例 #1
0
        private ParameterInfoCache[] GetParameterInfoCache(ParameterInfo[] parameters)
        {
            if (parameters == null || parameters.Length == 0)
            {
                return(null);
            }

            ParameterInfoCache[] parametersCache = new ParameterInfoCache[parameters.Length];

            for (int i = 0; i < parameters.Length; i++)
            {
                ParameterInfo parameterInfo = parameters[i];

                object[] injectAttributes = parameterInfo.GetCustomAttributes(typeof(InjectAttribute), true);

                InjectAttribute injectAttribute = null;

                if (injectAttributes.Length > 0)
                {
                    injectAttribute = (InjectAttribute)injectAttributes[0];
                }

                parametersCache[i] = new ParameterInfoCache(parameters[i], injectAttribute);
            }

            return(parametersCache);
        }
コード例 #2
0
        private MethodInfoCache FindConstructorMethodRecursive(Type type)
        {
            MethodInfo constructorMethodInfo = null;

            MethodInfo[] allStaticMethods = type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);

            foreach (var info in allStaticMethods)
            {
                if (info.GetCustomAttributes(typeof(ConstructorAttribute), true).Length <= 0)
                {
                    continue;
                }

                // Does it return an instance of itself?
                if (info.ReturnType == type)
                {
                    constructorMethodInfo = info;
                    break;
                }
            }

            if (constructorMethodInfo == null)
            {
                return(null);
            }

            ParameterInfo[] methodParameters = constructorMethodInfo.GetParameters();

            object[]        injectAttributes = constructorMethodInfo.GetCustomAttributes(typeof(InjectAttribute), true);
            InjectAttribute injectAttribute  = null;

            if (injectAttributes.Length > 0)
            {
                injectAttribute = (InjectAttribute)injectAttributes[0];
            }

            ParameterInfoCache[] parameters = GetParameterInfoCache(constructorMethodInfo.GetParameters());

            var constructorMethodInfoCache = new MethodInfoCache(constructorMethodInfo, injectAttribute, parameters);

            return(constructorMethodInfoCache);
        }
コード例 #3
0
        protected virtual List <MethodInfoCache> FindMethodsRecursive(Type type, List <MethodInfoCache> methods = null)
        {
            if (methods == null)
            {
                methods = new List <MethodInfoCache>();
            }

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

            foreach (var info in subMethods)
            {
                if (info.IsSpecialName || !MightHaveInjectAttribute(info))
                {
                    continue;
                }

                object[] injectAttributes = info.GetCustomAttributes(typeof(InjectAttribute), true);
                if (injectAttributes.Length <= 0)
                {
                    continue;
                }

                InjectAttribute injectAttribute = (InjectAttribute)injectAttributes[0];

                MethodInfoCache methodInfoCache = new MethodInfoCache(info, injectAttribute, GetParameterInfoCache(info.GetParameters()));

                methods.Add(methodInfoCache);
            }

            if (IsRootType(type.BaseType))
            {
                return(methods);
            }

            FindMethodsRecursive(type.BaseType, methods);

            return(methods);
        }
コード例 #4
0
 public ParameterInfoCache(ParameterInfo parameterInfo, InjectAttribute injectAttribute)
 {
     ParameterInfo   = parameterInfo;
     InjectAttribute = injectAttribute;
 }
コード例 #5
0
 public MemberInfoCache(MemberInfo memberInfo, InjectAttribute injectAttribute)
 {
     MemberInfo      = memberInfo;
     InjectAttribute = injectAttribute;
     DeclaringType   = memberInfo.DeclaringType;
 }