当前位置: 首页>>代码示例>>C#>>正文


C# IProxyGenerationHook.ShouldInterceptMethod方法代码示例

本文整理汇总了C#中IProxyGenerationHook.ShouldInterceptMethod方法的典型用法代码示例。如果您正苦于以下问题:C# IProxyGenerationHook.ShouldInterceptMethod方法的具体用法?C# IProxyGenerationHook.ShouldInterceptMethod怎么用?C# IProxyGenerationHook.ShouldInterceptMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IProxyGenerationHook的用法示例。


在下文中一共展示了IProxyGenerationHook.ShouldInterceptMethod方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AcceptMethod

        /// <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);
        }
开发者ID:mbrit,项目名称:MoqRTPOC,代码行数:58,代码来源:MembersCollector.cs

示例2: AcceptMethod

		/// <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);
		}
开发者ID:JulianBirch,项目名称:Castle.Core,代码行数:59,代码来源:MembersCollector.cs


注:本文中的IProxyGenerationHook.ShouldInterceptMethod方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。