我必须进行反射和后期绑定(bind),所以我不知道是否有办法加快速度。 我想我会试一试。
这个片段大约需要 15 秒才能完成,这太慢了,但看看我需要如何读取元数据。
private static object InvokeCall(Type HostObjectType, Object HostObject, CallType callType, string PropertyOrMethodName, object[] args)
{
if (callType == CallType.Method)
{
return MyObjectType.InvokeMember(PropertyOrMethodName,System.Reflection.BindingFlags.InvokeMethod, null, myObject, args);
}
}
最佳答案
查看Fasterflect - A Fast and Simple Reflection API和 Fast Invoker他们准备好使用解决方案并且对研究感兴趣。
想走自己的路看文章:Dodge Common Performance Pitfalls to Craft Speedy Applications和 Dynamically Compiled Lambdas vs. Pure Reflection
关于c# - InvokeMember 很慢,无论如何要避免这种情况?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3962066/