public static MethodMember CreateStubMethodMember(this MethodBase methodBase)
        {
            var visibility = methodBase.GetVisibility();

            var declaringType = methodBase.DeclaringType.CreateStubClass();
            var parameters    = methodBase.CreateStubParameters();
            var methodForm    = methodBase.GetStubMethodForm();

            Class  returnType = null;
            string fullName   = null;

            if (methodBase is ConstructorInfo constructor)
            {
                returnType = typeof(void).CreateStubClass();
                fullName   = constructor.CreateStubFullName(returnType);
            }

            if (methodBase is MethodInfo methodInfo)
            {
                returnType = methodInfo.ReturnType.CreateStubClass();
                fullName   = methodInfo.CreateStubFullName();
            }

            return(new MethodMember(methodBase.BuildMockMethodName(), fullName, declaringType, visibility, parameters,
                                    returnType, methodBase.IsVirtual, methodForm, new List <GenericParameter>()));
        }
Example #2
0
        public static MethodMember CreateStubMethodMember(this MethodBase methodBase)
        {
            var visibility = methodBase.GetVisibility();

            var declaringType = methodBase.DeclaringType.CreateStubClass();
            var parameters    = methodBase.CreateStubParameters().Select(parameter => new TypeInstance <IType>(parameter));
            var methodForm    = methodBase.GetStubMethodForm();

            var isGeneric = methodBase.IsGenericMethod;

            TypeInstance <IType> returnTypeInstance = null;
            string fullName = null;

            if (methodBase is ConstructorInfo constructor)
            {
                var voi = typeof(void).CreateStubClass();
                returnTypeInstance = new TypeInstance <IType>(voi);
                fullName           = constructor.CreateStubFullName(voi);
            }

            if (methodBase is MethodInfo methodInfo)
            {
                var returnType = methodInfo.ReturnType.CreateStubClass();
                returnTypeInstance = new TypeInstance <IType>(returnType);
                fullName           = methodInfo.CreateStubFullName();
            }

            var methodMember = new MethodMember(methodBase.BuildMockMethodName(), fullName, declaringType, visibility,
                                                returnTypeInstance, methodBase.IsVirtual, methodForm, isGeneric, false, false, false);

            methodMember.ParameterInstances.AddRange(parameters);
            return(methodMember);
        }