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


C# MethodBase.IsInheritable方法代码示例

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


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

示例1: CheckInstrumentationAvailability

		private static void CheckInstrumentationAvailability(MethodBase value)
		{
			if (IsInterceptedAtTheCallSite(value))
			{
				return;
			}

#if !PORTABLE
			var methodImpl = value.GetMethodImplementationFlags();
			if ((((methodImpl & MethodImplAttributes.InternalCall) != 0
				   || (methodImpl & MethodImplAttributes.CodeTypeMask) != MethodImplAttributes.IL)
				  && value.Module.Assembly == typeof(object).Assembly)
				  && !value.IsInheritable())
				throw new MockException("Cannot mock a method that is implemented internally by the CLR.");
#endif

			if (!value.IsInheritable() && !ProfilerInterceptor.TypeSupportsInstrumentation(value.DeclaringType))
				throw new MockException(String.Format("Cannot mock non-inheritable member '{0}' on type '{1}' due to CLR limitations.", value, value.DeclaringType));

			if ((value.Attributes & MethodAttributes.PinvokeImpl) != 0)
			{
				if (!ProfilerInterceptor.IsProfilerAttached)
					throw new MockException("The profiler must be enabled to mock DllImport methods.");

				string fullName = value.DeclaringType.FullName + "." + value.Name;
				if ((value.Attributes & MethodAttributes.HasSecurity) != 0)
					throw new MockException(string.Format("DllImport method {0} cannot be mocked because it has security information attached.", fullName));

				// method could be the profiler generated shadow method or is inside an assembly which doesn't contain managed code (valid RVA)
				throw new MockException(string.Format("DllImport method {0} cannot be mocked due to internal limitation.", fullName));
			}

			if (uninterceptedMethods.Contains(value))
				throw new MockException("Cannot mock Object..ctor, Object.Equals, Object.ReferenceEquals or Finalize");

			var asMethodInfo = value as MethodInfo;
			if (asMethodInfo != null)
			{
				if (uninterceptedMethods.Contains(asMethodInfo.GetBaseDefinition()))
					throw new MockException("Cannot mock Object.Equals, Object.ReferenceEquals or Finalize");
			}
		}
开发者ID:ArthurYiL,项目名称:JustMockLite,代码行数:42,代码来源:CallPattern.cs


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