<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />

LateBoundReflectionDelegateFactory

using Newtonsoft.Json.Serialization; using System; using System.Reflection; using System.Runtime.CompilerServices; namespace Newtonsoft.Json.Utilities { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] internal class LateBoundReflectionDelegateFactory : ReflectionDelegateFactory { private static readonly LateBoundReflectionDelegateFactory _instance = new LateBoundReflectionDelegateFactory(); internal static ReflectionDelegateFactory Instance => _instance; public override ObjectConstructor<object> CreateParameterizedConstructor(MethodBase method) { ValidationUtils.ArgumentNotNull(method, "method"); ConstructorInfo c = method as ConstructorInfo; if ((object)c != null) return (object[] a) => c.Invoke(a); return (object[] a) => method.Invoke(null, a); } [return: System.Runtime.CompilerServices.Nullable(new byte[] { 1, 1, 2 })] public override MethodCall<T, object> CreateMethodCall<[System.Runtime.CompilerServices.Nullable(2)] T>(MethodBase method) { ValidationUtils.ArgumentNotNull(method, "method"); ConstructorInfo c = method as ConstructorInfo; if ((object)c != null) return (T o, object[] a) => c.Invoke(a); return (T o, object[] a) => method.Invoke(o, a); } public override Newtonsoft.Json.Serialization.Func<T> CreateDefaultConstructor<[System.Runtime.CompilerServices.Nullable(2)] T>(Type type) { ValidationUtils.ArgumentNotNull(type, "type"); if (type.IsValueType()) return () => (T)Activator.CreateInstance(type); ConstructorInfo constructorInfo = ReflectionUtils.GetDefaultConstructor(type, true); if ((object)constructorInfo == null) throw new InvalidOperationException("Unable to find default constructor for " + type.FullName); return () => (T)constructorInfo.Invoke(null); } [return: System.Runtime.CompilerServices.Nullable(new byte[] { 1, 1, 2 })] public override Newtonsoft.Json.Serialization.Func<T, object> CreateGet<[System.Runtime.CompilerServices.Nullable(2)] T>(PropertyInfo propertyInfo) { ValidationUtils.ArgumentNotNull(propertyInfo, "propertyInfo"); return (T o) => propertyInfo.GetValue(o, null); } [return: System.Runtime.CompilerServices.Nullable(new byte[] { 1, 1, 2 })] public override Newtonsoft.Json.Serialization.Func<T, object> CreateGet<[System.Runtime.CompilerServices.Nullable(2)] T>(FieldInfo fieldInfo) { ValidationUtils.ArgumentNotNull(fieldInfo, "fieldInfo"); return (T o) => fieldInfo.GetValue(o); } [return: System.Runtime.CompilerServices.Nullable(new byte[] { 1, 1, 2 })] public override Newtonsoft.Json.Serialization.Action<T, object> CreateSet<[System.Runtime.CompilerServices.Nullable(2)] T>(FieldInfo fieldInfo) { ValidationUtils.ArgumentNotNull(fieldInfo, "fieldInfo"); return delegate(T o, object v) { fieldInfo.SetValue(o, v); }; } [return: System.Runtime.CompilerServices.Nullable(new byte[] { 1, 1, 2 })] public override Newtonsoft.Json.Serialization.Action<T, object> CreateSet<[System.Runtime.CompilerServices.Nullable(2)] T>(PropertyInfo propertyInfo) { ValidationUtils.ArgumentNotNull(propertyInfo, "propertyInfo"); return delegate(T o, object v) { propertyInfo.SetValue(o, v, null); }; } } }