【C#】使用DynamicMethod代替PropertyInfo.Get/SetValue提高性能
上代码
DynamicMethodHelper
namespace System.Reflection.Emit
{
public static class DynamicMethodHelper
{
private static readonly Dictionary<string, Action<object, object>> _dynamicMethods = new Dictionary<string, Action<object, object>>();
private static readonly Dictionary<string, Func<object, object>> _dynamicGetMethods = new Dictionary<string, Func<object, object>>();
private static readonly object _lockObj = new object();
private static readonly object _lockSetObj = new object();
private static string ResolveSetName(PropertyInfo propertyInfo, Type type) => $"{
type.FullName}_set_{
propertyInfo.Name}";
public static Action<object, object> ResolveSetValueMethod<T>(PropertyInfo property) => ResolveSetValueMethod(property, typeof(T));
public static Action<