/// <summary>
        /// Performs some basic screening and invokes the <see cref="IProxyGenerationHook"/>
        /// to select methods.
        /// </summary>
        /// <param name="method"></param>
        /// <param name="onlyVirtuals"></param>
        /// <param name="hook"></param>
        /// <returns></returns>
        protected bool AcceptMethod(MethodInfo method, bool onlyVirtuals, IProxyGenerationHook hook)
        {
            // we can never intercept a sealed (final) method
            if (method.IsFinal)
            {
                Logger.Debug("Excluded sealed method {0} on {1} because it cannot be intercepted.", method.Name, method.DeclaringType.FullName);
                return(false);
            }

            bool isInternalsAndNotVisibleToDynamicProxy = InternalsHelper.IsInternal(method);

            if (isInternalsAndNotVisibleToDynamicProxy)
            {
                isInternalsAndNotVisibleToDynamicProxy = InternalsHelper.IsInternalToDynamicProxy(method.DeclaringType.Assembly) ==
                                                         false;
            }

            if (isInternalsAndNotVisibleToDynamicProxy)
            {
                return(false);
            }

            if (onlyVirtuals && !method.IsVirtual)
            {
#if SILVERLIGHT
                if (method.DeclaringType != typeof(object))
#else
                if (method.DeclaringType != typeof(object) && method.DeclaringType != typeof(MarshalByRefObject))
#endif
                {
                    Logger.Debug("Excluded non-virtual method {0} on {1} because it cannot be intercepted.", method.Name, method.DeclaringType.FullName);
                    hook.NonVirtualMemberNotification(type, method);
                }

                return(false);
            }

            //can only proxy methods that are public or protected (or internals that have already been checked above)
            if ((method.IsPublic || method.IsFamily || method.IsAssembly || method.IsFamilyOrAssembly) == false)
            {
                return(false);
            }

            if (method.DeclaringType == typeof(object))
            {
                return(false);
            }

#if !SILVERLIGHT
            if (method.DeclaringType == typeof(MarshalByRefObject))
            {
                return(false);
            }
#endif
            return(hook.ShouldInterceptMethod(type, method));
        }
Example #2
0
        /// <summary>
        ///   Performs some basic screening and invokes the <see cref = "IProxyGenerationHook" />
        ///   to select methods.
        /// </summary>
        /// <param name = "method"></param>
        /// <param name = "onlyVirtuals"></param>
        /// <param name = "hook"></param>
        /// <returns></returns>
        protected bool AcceptMethod(MethodInfo method, bool onlyVirtuals, IProxyGenerationHook hook)
        {
            if (IsInternalAndNotVisibleToDynamicProxy(method))
            {
                return(false);
            }

            var isOverridable = method.IsVirtual && !method.IsFinal;

            if (onlyVirtuals && !isOverridable)
            {
                if (
#if !SILVERLIGHT
                    method.DeclaringType != typeof(MarshalByRefObject) &&
#endif
                    method.IsGetType() == false &&
                    method.IsMemberwiseClone() == false)
                {
                    Logger.DebugFormat("Excluded non-overridable method {0} on {1} because it cannot be intercepted.", method.Name,
                                       method.DeclaringType.FullName);
                    hook.NonProxyableMemberNotification(type, method);
                }
                return(false);
            }

            // we can never intercept a sealed (final) method
            if (method.IsFinal)
            {
                Logger.DebugFormat("Excluded sealed method {0} on {1} because it cannot be intercepted.", method.Name,
                                   method.DeclaringType.FullName);
                return(false);
            }

            //can only proxy methods that are public or protected (or internals that have already been checked above)
            if ((method.IsPublic || method.IsFamily || method.IsAssembly || method.IsFamilyOrAssembly) == false)
            {
                return(false);
            }

#if !SILVERLIGHT
            if (method.DeclaringType == typeof(MarshalByRefObject))
            {
                return(false);
            }
#endif
            if (method.IsFinalizer())
            {
                return(false);
            }

            return(hook.ShouldInterceptMethod(type, method));
        }
        public bool ShouldInterceptMethod(Type type, MethodInfo methodInfo)
        {
            if (IsChannelHolderMethod(methodInfo))
            {
                return(false);
            }

            if (hook != null)
            {
                return(hook.ShouldInterceptMethod(type, methodInfo));
            }

            return(true);
        }
Example #4
0
        public bool ShouldInterceptMethod(Type type, MethodInfo methodInfo)
        {
            // NOTE: This is fixed now. This code can be uncommented and Selector does not have to have this responsibility anymore
            // BUG: Due to... illogical behavior of DP this will produce illformed proxy types.
            // We have to move this piece of logic to InterceptorSelector, and move it back when the bug gets fixed.
            //if (IsChannelHolderMethod(methodInfo))
            //{
            //    return false;
            //}

            if (hook != null)
            {
                return(hook.ShouldInterceptMethod(type, methodInfo));
            }

            return(true);
        }
        protected override MetaMethod GetMethodToGenerate(MethodInfo method, IProxyGenerationHook hook, bool isStandalone)
        {
            if (ProxyUtil.IsAccessibleMethod(method) == false)
            {
                return(null);
            }

            var interceptable = AcceptMethodPreScreen(method, true, hook);

            if (!interceptable)
            {
                //we don't need to do anything...
                return(null);
            }

            var accepted = hook.ShouldInterceptMethod(type, method);

            return(new MetaMethod(method, method, isStandalone, accepted, hasTarget: true));
        }
Example #6
0
        /// <summary>
        ///   Performs some basic screening and invokes the <see cref = "IProxyGenerationHook" />
        ///   to select methods.
        /// </summary>
        /// <param name = "method"></param>
        /// <param name = "onlyVirtuals"></param>
        /// <param name = "hook"></param>
        /// <returns></returns>
        protected bool AcceptMethod(MethodInfo method, bool onlyVirtuals, IProxyGenerationHook hook)
        {
            // we can never intercept a sealed (final) method
            if (method.IsFinal)
            {
                Logger.DebugFormat("Excluded sealed method {0} on {1} because it cannot be intercepted.", method.Name,
                                   method.DeclaringType.FullName);
                return false;
            }

            if (IsInternalAndNotVisibleToDynamicProxy(method))
            {
                return false;
            }

            if (onlyVirtuals && !method.IsVirtual)
            {
                if (
            #if !SILVERLIGHT
                    method.DeclaringType != typeof(MarshalByRefObject) &&
            #endif
                    method.IsGetType() == false &&
                    method.IsMemberwiseClone() == false)
                {
                    Logger.DebugFormat("Excluded non-virtual method {0} on {1} because it cannot be intercepted.", method.Name,
                                       method.DeclaringType.FullName);
                    hook.NonProxyableMemberNotification(type, method);
                }
                return false;
            }

            //can only proxy methods that are public or protected (or internals that have already been checked above)
            if ((method.IsPublic || method.IsFamily || method.IsAssembly || method.IsFamilyOrAssembly) == false)
            {
                return false;
            }

            #if !SILVERLIGHT
            if (method.DeclaringType == typeof(MarshalByRefObject))
            {
                return false;
            }
            #endif
            if (method.IsFinalizer())
            {
                return false;
            }

            return hook.ShouldInterceptMethod(type, method);
        }
		/// <summary>
		/// Performs some basic screening and invokes the <see cref="IProxyGenerationHook"/>
		/// to select methods.
		/// </summary>
		/// <param name="method"></param>
		/// <param name="onlyVirtuals"></param>
		/// <param name="hook"></param>
		/// <returns></returns>
		protected bool AcceptMethod(MethodInfo method, bool onlyVirtuals, IProxyGenerationHook hook)
		{
			// we can never intercept a sealed (final) method
			if (method.IsFinal)
			{
				Logger.Debug("Excluded sealed method {0} on {1} because it cannot be intercepted.", method.Name, method.DeclaringType.FullName);
				return false;
			}

			bool isInternalsAndNotVisibleToDynamicProxy = InternalsHelper.IsInternal(method);
			if (isInternalsAndNotVisibleToDynamicProxy)
			{
				isInternalsAndNotVisibleToDynamicProxy = InternalsHelper.IsInternalToDynamicProxy(method.DeclaringType.Assembly) ==
				                                         false;
			}

			if (isInternalsAndNotVisibleToDynamicProxy)
				return false;

			if (onlyVirtuals && !method.IsVirtual)
			{
#if SILVERLIGHT
				if (method.DeclaringType != typeof(object))
#else
				if (method.DeclaringType != typeof(object) && method.DeclaringType != typeof(MarshalByRefObject))
#endif
				{
					Logger.Debug("Excluded non-virtual method {0} on {1} because it cannot be intercepted.", method.Name, method.DeclaringType.FullName);
					hook.NonVirtualMemberNotification(type, method);
				}

				return false;
			}

			//can only proxy methods that are public or protected (or internals that have already been checked above)
			if ((method.IsPublic || method.IsFamily || method.IsAssembly || method.IsFamilyOrAssembly) == false)
				return false;

			if (method.DeclaringType == typeof (object))
			{
				return false;
			}

#if !SILVERLIGHT
			if (method.DeclaringType == typeof (MarshalByRefObject))
			{
				return false;
			}
#endif
			return hook.ShouldInterceptMethod(type, method);
		}
 public override bool ShouldInterceptMethod(Type type, MethodInfo methodInfo)
 {
     return(_episerverInternalHook.ShouldInterceptMethod(type, methodInfo) || IsEPiProperty(type, methodInfo));
 }
Example #9
0
 /// <summary>
 ///   Performs some basic screening and invokes the <see cref = "IProxyGenerationHook" />
 ///   to select methods.
 /// </summary>
 protected bool AcceptMethod(MethodInfo method, bool onlyVirtuals, IProxyGenerationHook hook)
 {
     return(AcceptMethodPreScreen(method, onlyVirtuals, hook) && hook.ShouldInterceptMethod(type, method));
 }