System.Delegate.CreateDelegate 方法 (Type, Type, String, Boolean, Boolean)

方法描述

使用用于指定是否区分大小写的值和针对绑定失败的指定行为,创建指定类型的委托,该委托表示指定类的指定静态方法。

语法定义(C# System.Delegate.CreateDelegate 方法 (Type, Type, String, Boolean, Boolean) 的用法)

public static Delegate CreateDelegate(
	Type type,
	Type target,
	string method,
	bool ignoreCase,
	bool throwOnBindFailure
)

参数/返回值

参数值/返回值 参数类型/返回类型 参数描述/返回描述
type System-Type 要创建的委托的 Type。
target System-Type 表示实现 method 的类的 Type。
method System-String 委托要表示的静态方法的名称。
ignoreCase System-Boolean 一个布尔值,它指示在比较方法名称时是否忽略大小写。
throwOnBindFailure System-Boolean 为 true,表示无法绑定 method 时引发异常;否则为 false。
返回值 System.Delegate 指定类型的委托,该委托表示指定类的指定静态方法。

提示和注释

此方法只为静态方法创建委托。 实例方法是指与类的实例相关联的方法;静态方法是指与类本身相关联的方法。

注意

从 .NET Framework 2.0 版 Service Pack 1 开始,如果已授予调用方带有 ReflectionPermissionFlag.RestrictedMemberAccess 标志的 ReflectionPermission,并且非公共方法的授予集限制为调用方的授予集或其子集,则此方法可用于访问非公共方法。 (请参见 反射的安全注意事项。)

若要使用此功能,您的应用程序应面向 .NET Framework 3.5 版 或更高版本。

System.Delegate.CreateDelegate 方法 (Type, Type, String, Boolean, Boolean)例子


异常

异常 异常描述
ArgumentNullException
  • type 为 null。
  • target 为 null。
  • method 为 null。
ArgumentException
  • type 不继承 MulticastDelegate。
  • type 不是 RuntimeType。 请参见反射中的运行时类型。
  • target 不是 RuntimeType。
  • target 是一个开放式泛型类型。 即,其 ContainsGenericParameters 属性为 true。
  • method 不是 static 方法(在 Visual Basic 中为 Shared 方法)。
  • 无法绑定 method,因为找不到它并且 throwOnBindFailure 为 true(举例来说)。
MissingMethodException 未找到 type 的 Invoke 方法。
MethodAccessException 调用方无权访问 method。

命名空间

namespace: System

程序集: mscorlib(在 mscorlib.dll 中)

版本信息

.NET Framework 受以下版本支持:4、3.5、3.0、2.0 .NET Framework Client Profile 受以下版本支持:4、3.5 SP1

适用平台

Windows 7, Windows Vista SP1 或更高版本, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008(不支持服务器核心), Windows Server 2008 R2(支持 SP1 或更高版本的服务器核心), Windows Server 2003 SP2 .NET Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。