Ejemplo n.º 1
0
        /// <summary>
        /// Returns an existing or creates a new implementation (or re-implementation) for <paramref name="interfaceMethod"/>.
        /// Note that the specified implementation is not invoked if a final base implementation is invoked directly (not via the interface).
        /// </summary>
        /// <param name="interfaceMethod">The interface method that should be implemented.</param>
        /// <returns>A <see cref="MutableMethodInfo"/> that is an implementation of the interface method.</returns>
        /// <exception cref="NotSupportedException">
        /// If the specified method cannot be implemented (or re-implemented), e.g., it is not accessible from the proxy.
        /// </exception>
        /// <remarks>
        /// This method returns one of the following:
        /// <list type="number">
        ///   <item>An existing mutable implementation.</item>
        ///   <item>A newly created implementation (if no base implementation).</item>
        ///   <item>An existing mutable override for a base implementation.</item>
        ///   <item>A newly created override (implicit; or explicit if necessary) for a base implementation (if base implementation is not final).</item>
        ///   <item>A newly created re-implementation which calls the base implementation.</item>
        /// </list>
        /// </remarks>
        public MutableMethodInfo GetOrAddImplementation(MethodInfo interfaceMethod)
        {
            ArgumentUtility.CheckNotNull("interfaceMethod", interfaceMethod);

            bool isNewlyCreated;
            var  method = _mutableMemberFactory.GetOrCreateImplementation(this, interfaceMethod, out isNewlyCreated);

            if (isNewlyCreated)
            {
                AddTrackedMethod(method);
            }

            return(method);
        }