高性能的反射工具类

ClownFish提供了以下工具来优化反射调用的性能:



对象构造

public static class CtorExtensions
{
	/// <summary>
	/// 快速实例化一个对象
	/// </summary>
	/// <param name="instanceType"></param>
	/// <returns></returns>
	public static object FastNew(this Type instanceType)

}



Field读写

public static class FieldInfoExtensions
{
	/// <summary>
	/// 快速读取字段值
	/// </summary>
	/// <param name="fieldInfo"></param>
	/// <param name="instance"></param>
	/// <returns></returns>
	public static object FastGetValue(this FieldInfo fieldInfo, object instance)


	/// <summary>
	/// 快速给字段赋值
	/// </summary>
	/// <param name="fieldInfo"></param>
	/// <param name="instance"></param>
	/// <param name="value"></param>
	public static void FastSetValue(this FieldInfo fieldInfo, object instance, object value)

}



Property读写

public static class PropertyInfoExtensions
{
	/// <summary>
	/// 快速读取属性值
	/// </summary>
	/// <param name="propertyInfo"></param>
	/// <param name="instance"></param>
	/// <returns></returns>
	public static object FastGetValue(this PropertyInfo propertyInfo, object instance)

	/// <summary>
	/// 快速给属性赋值
	/// </summary>
	/// <param name="propertyInfo"></param>
	/// <param name="instance"></param>
	/// <param name="value"></param>
	public static void FastSetValue(this PropertyInfo propertyInfo, object instance, object value)
}



方法调用

public static class MethodInfoExtensions
{
	/// <summary>
	/// 快速调用方法
	/// </summary>
	/// <param name="methodInfo"></param>
	/// <param name="instance"></param>
	/// <param name="parameters"></param>
	/// <returns></returns>
	public static object FastInvoke(this MethodInfo methodInfo, object instance, params object[] parameters)
}