Example #1
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));
        }
Example #2
0
        public Expression InvokePreviousBodyWithArguments(IEnumerable <Expression> arguments)
        {
            ArgumentUtility.CheckNotNull("arguments", arguments);

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