private static ConstructorInfo GetConstructor(Type type, ICollection <Expression> arguments)
        {
            var argumentTypes = BodyContextUtility.GetArgumentTypes(arguments);
            var constructor   = type.GetConstructor(c_allInstanceMembers, null, argumentTypes, null);

            if (constructor == null)
            {
                var message = String.Format(
                    "Could not find an instance constructor with signature ({0}) on type '{1}'.", string.Join(", ", (IEnumerable <Type>)argumentTypes), type.Name);
                throw new MissingMemberException(message);
            }

            return(constructor);
        }
Пример #2
0
        public Expression CopyMethodBody(MutableMethodInfo otherMethod, IEnumerable <Expression> arguments)
        {
            ArgumentUtility.CheckNotNull("otherMethod", otherMethod);
            ArgumentUtility.CheckNotNull("arguments", arguments);

            // ReSharper disable PossibleUnintendedReferenceComparison
            if (otherMethod.DeclaringType != _declaringType)
            // ReSharper restore PossibleUnintendedReferenceComparison
            {
                var message = string.Format("The specified method is declared by a different type '{0}'.", otherMethod.DeclaringType);
                throw new ArgumentException(message, "otherMethod");
            }

            if (IsStatic && !otherMethod.IsStatic)
            {
                throw new ArgumentException("The body of an instance method cannot be copied into a static method.", "otherMethod");
            }

            return(BodyContextUtility.ReplaceParameters(otherMethod.ParameterExpressions, otherMethod.Body, arguments));
        }
Пример #3
0
        public Expression InvokePreviousBodyWithArguments(IEnumerable <Expression> arguments)
        {
            ArgumentUtility.CheckNotNull("arguments", arguments);

            return(BodyContextUtility.ReplaceParameters(Parameters, PreviousBody, arguments));
        }