Esempio n. 1
0
        public MethodInfo GetMethod(Type[] genericTypes)
        {
            foreach (var methodInfo in ImplementingType.GetMethods(BindingFlags.Public | BindingFlags.Static))
            {
                var parameters = methodInfo.GetParameters();
                if (parameters.Length != 2)
                {
                    continue;
                }
                if (parameters[1].ParameterType != typeof(IContext))
                {
                    continue;
                }

                var genericArguments = methodInfo.GetGenericArguments();
                if (genericArguments.Length != genericTypes.Length)
                {
                    continue;
                }

                return(methodInfo.MakeGenericMethod(genericTypes));
            }

            throw new MissingMethodException(ImplementingType.Name, "Implementation");
        }
Esempio n. 2
0
        public MethodInfo GetMethod()
        {
            foreach (var methodInfo in ImplementingType.GetMethods(BindingFlags.Public | BindingFlags.Static))
            {
                var parameters = methodInfo.GetParameters();
                if (parameters.Length == 2 && parameters[1].ParameterType == typeof(IContext))
                {
                    if (parameters[0].ParameterType == BehaviorType)
                    {
                        return(methodInfo);
                    }

                    if (parameters[0].ParameterType.IsGenericType && BehaviorType.IsGenericType)
                    {
                        if (parameters[0].ParameterType.GetGenericTypeDefinition() == BehaviorType.GetGenericTypeDefinition())
                        {
                            return(methodInfo);
                        }
                    }
                }
            }

            throw new MissingMethodException(ImplementingType.Name, "Implementation");
        }