| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | #if NETFRAMEWORK || NET |
| | | 5 | | using System.Collections.Generic; |
| | | 6 | | using System.Diagnostics; |
| | | 7 | | using System.Diagnostics.CodeAnalysis; |
| | | 8 | | using System.Reflection; |
| | | 9 | | using System.Reflection.Emit; |
| | | 10 | | |
| | | 11 | | namespace System.Text.Json.Serialization.Metadata |
| | | 12 | | { |
| | | 13 | | [RequiresDynamicCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] |
| | | 14 | | [RequiresUnreferencedCode(JsonSerializer.SerializationRequiresDynamicCodeMessage)] |
| | | 15 | | internal sealed class ReflectionEmitMemberAccessor : MemberAccessor |
| | | 16 | | { |
| | 1 | 17 | | public ReflectionEmitMemberAccessor() |
| | 1 | 18 | | { |
| | 1 | 19 | | } |
| | | 20 | | |
| | | 21 | | public override Func<object>? CreateParameterlessConstructor(Type type, ConstructorInfo? constructorInfo) |
| | 3340 | 22 | | { |
| | 3340 | 23 | | Debug.Assert(type != null); |
| | 3340 | 24 | | Debug.Assert(constructorInfo is null || constructorInfo.GetParameters().Length == 0); |
| | | 25 | | |
| | 3340 | 26 | | if (type.IsAbstract) |
| | 88 | 27 | | { |
| | 88 | 28 | | return null; |
| | | 29 | | } |
| | | 30 | | |
| | 3252 | 31 | | if (constructorInfo is null && !type.IsValueType) |
| | 995 | 32 | | { |
| | 995 | 33 | | return null; |
| | | 34 | | } |
| | | 35 | | |
| | 2257 | 36 | | var dynamicMethod = new DynamicMethod( |
| | 2257 | 37 | | ConstructorInfo.ConstructorName, |
| | 2257 | 38 | | JsonTypeInfo.ObjectType, |
| | 2257 | 39 | | Type.EmptyTypes, |
| | 2257 | 40 | | typeof(ReflectionEmitMemberAccessor).Module, |
| | 2257 | 41 | | skipVisibility: true); |
| | | 42 | | |
| | 2257 | 43 | | ILGenerator generator = dynamicMethod.GetILGenerator(); |
| | | 44 | | |
| | 2257 | 45 | | if (constructorInfo is null) |
| | 1169 | 46 | | { |
| | 1169 | 47 | | Debug.Assert(type.IsValueType); |
| | | 48 | | |
| | 1169 | 49 | | LocalBuilder local = generator.DeclareLocal(type); |
| | | 50 | | |
| | 1169 | 51 | | generator.Emit(OpCodes.Ldloca_S, local); |
| | 1169 | 52 | | generator.Emit(OpCodes.Initobj, type); |
| | 1169 | 53 | | generator.Emit(OpCodes.Ldloc, local); |
| | 1169 | 54 | | generator.Emit(OpCodes.Box, type); |
| | 1169 | 55 | | } |
| | | 56 | | else |
| | 1088 | 57 | | { |
| | 1088 | 58 | | generator.Emit(OpCodes.Newobj, constructorInfo); |
| | 1088 | 59 | | if (type.IsValueType) |
| | 0 | 60 | | { |
| | | 61 | | // Since C# 10 it's now possible to have parameterless constructors in structs |
| | 0 | 62 | | generator.Emit(OpCodes.Box, type); |
| | 0 | 63 | | } |
| | 1088 | 64 | | } |
| | | 65 | | |
| | 2257 | 66 | | generator.Emit(OpCodes.Ret); |
| | | 67 | | |
| | 2257 | 68 | | return CreateDelegate<Func<object>>(dynamicMethod); |
| | 3340 | 69 | | } |
| | | 70 | | |
| | | 71 | | public override Func<object[], T> CreateParameterizedConstructor<T>(ConstructorInfo constructor) => |
| | 738 | 72 | | CreateDelegate<Func<object[], T>>(CreateParameterizedConstructor(constructor)); |
| | | 73 | | |
| | | 74 | | private static DynamicMethod CreateParameterizedConstructor(ConstructorInfo constructor) |
| | 738 | 75 | | { |
| | 738 | 76 | | Type? type = constructor.DeclaringType; |
| | | 77 | | |
| | 738 | 78 | | Debug.Assert(type != null); |
| | 738 | 79 | | Debug.Assert(!type.IsAbstract); |
| | 738 | 80 | | Debug.Assert(constructor.IsPublic && !constructor.IsStatic); |
| | | 81 | | |
| | 738 | 82 | | ParameterInfo[] parameters = constructor.GetParameters(); |
| | 738 | 83 | | int parameterCount = parameters.Length; |
| | | 84 | | |
| | 738 | 85 | | var dynamicMethod = new DynamicMethod( |
| | 738 | 86 | | ConstructorInfo.ConstructorName, |
| | 738 | 87 | | type, |
| | 738 | 88 | | new[] { typeof(object[]) }, |
| | 738 | 89 | | typeof(ReflectionEmitMemberAccessor).Module, |
| | 738 | 90 | | skipVisibility: true); |
| | | 91 | | |
| | 738 | 92 | | ILGenerator generator = dynamicMethod.GetILGenerator(); |
| | | 93 | | |
| | 10332 | 94 | | for (int i = 0; i < parameterCount; i++) |
| | 4428 | 95 | | { |
| | 4428 | 96 | | Type paramType = parameters[i].ParameterType; |
| | | 97 | | |
| | 4428 | 98 | | generator.Emit(OpCodes.Ldarg_0); |
| | 4428 | 99 | | generator.Emit(OpCodes.Ldc_I4, i); |
| | 4428 | 100 | | generator.Emit(OpCodes.Ldelem_Ref); |
| | 4428 | 101 | | generator.Emit(OpCodes.Unbox_Any, paramType); |
| | 4428 | 102 | | } |
| | | 103 | | |
| | 738 | 104 | | generator.Emit(OpCodes.Newobj, constructor); |
| | 738 | 105 | | generator.Emit(OpCodes.Ret); |
| | | 106 | | |
| | 738 | 107 | | return dynamicMethod; |
| | 738 | 108 | | } |
| | | 109 | | |
| | | 110 | | public override JsonTypeInfo.ParameterizedConstructorDelegate<T, TArg0, TArg1, TArg2, TArg3>? |
| | | 111 | | CreateParameterizedConstructor<T, TArg0, TArg1, TArg2, TArg3>(ConstructorInfo constructor) => |
| | 0 | 112 | | CreateDelegate<JsonTypeInfo.ParameterizedConstructorDelegate<T, TArg0, TArg1, TArg2, TArg3>>( |
| | 0 | 113 | | CreateParameterizedConstructor(constructor, typeof(TArg0), typeof(TArg1), typeof(TArg2), typeof(TArg3))) |
| | | 114 | | |
| | | 115 | | private static DynamicMethod? CreateParameterizedConstructor(ConstructorInfo constructor, Type parameterType1, T |
| | 0 | 116 | | { |
| | 0 | 117 | | Type? type = constructor.DeclaringType; |
| | | 118 | | |
| | 0 | 119 | | Debug.Assert(type != null); |
| | 0 | 120 | | Debug.Assert(!type.IsAbstract); |
| | 0 | 121 | | Debug.Assert(!constructor.IsStatic); |
| | | 122 | | |
| | 0 | 123 | | ParameterInfo[] parameters = constructor.GetParameters(); |
| | 0 | 124 | | int parameterCount = parameters.Length; |
| | | 125 | | |
| | 0 | 126 | | var dynamicMethod = new DynamicMethod( |
| | 0 | 127 | | ConstructorInfo.ConstructorName, |
| | 0 | 128 | | type, |
| | 0 | 129 | | new[] { parameterType1, parameterType2, parameterType3, parameterType4 }, |
| | 0 | 130 | | typeof(ReflectionEmitMemberAccessor).Module, |
| | 0 | 131 | | skipVisibility: true); |
| | | 132 | | |
| | 0 | 133 | | ILGenerator generator = dynamicMethod.GetILGenerator(); |
| | | 134 | | |
| | 0 | 135 | | for (int index = 0; index < parameterCount; index++) |
| | 0 | 136 | | { |
| | 0 | 137 | | Debug.Assert(index <= JsonConstants.UnboxedParameterCountThreshold); |
| | | 138 | | |
| | 0 | 139 | | generator.Emit( |
| | 0 | 140 | | index switch |
| | 0 | 141 | | { |
| | 0 | 142 | | 0 => OpCodes.Ldarg_0, |
| | 0 | 143 | | 1 => OpCodes.Ldarg_1, |
| | 0 | 144 | | 2 => OpCodes.Ldarg_2, |
| | 0 | 145 | | 3 => OpCodes.Ldarg_3, |
| | 0 | 146 | | _ => throw new InvalidOperationException() |
| | 0 | 147 | | }); |
| | 0 | 148 | | } |
| | | 149 | | |
| | 0 | 150 | | generator.Emit(OpCodes.Newobj, constructor); |
| | 0 | 151 | | generator.Emit(OpCodes.Ret); |
| | | 152 | | |
| | 0 | 153 | | return dynamicMethod; |
| | 0 | 154 | | } |
| | | 155 | | |
| | | 156 | | public override Action<TCollection, object?> CreateAddMethodDelegate<[DynamicallyAccessedMembers(DynamicallyAcce |
| | 0 | 157 | | CreateDelegate<Action<TCollection, object?>>(CreateAddMethodDelegate(typeof(TCollection))); |
| | | 158 | | |
| | | 159 | | private static DynamicMethod CreateAddMethodDelegate( |
| | | 160 | | [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] Type collectionType) |
| | 0 | 161 | | { |
| | | 162 | | // We verified this won't be null when we created the converter that calls this method. |
| | 0 | 163 | | MethodInfo realMethod = (collectionType.GetMethod("Push") ?? collectionType.GetMethod("Enqueue"))!; |
| | | 164 | | |
| | 0 | 165 | | var dynamicMethod = new DynamicMethod( |
| | 0 | 166 | | realMethod.Name, |
| | 0 | 167 | | typeof(void), |
| | 0 | 168 | | new[] { collectionType, JsonTypeInfo.ObjectType }, |
| | 0 | 169 | | typeof(ReflectionEmitMemberAccessor).Module, |
| | 0 | 170 | | skipVisibility: true); |
| | | 171 | | |
| | 0 | 172 | | ILGenerator generator = dynamicMethod.GetILGenerator(); |
| | | 173 | | |
| | 0 | 174 | | generator.Emit(OpCodes.Ldarg_0); |
| | 0 | 175 | | generator.Emit(OpCodes.Ldarg_1); |
| | 0 | 176 | | generator.Emit(OpCodes.Callvirt, realMethod); |
| | 0 | 177 | | generator.Emit(OpCodes.Ret); |
| | | 178 | | |
| | 0 | 179 | | return dynamicMethod; |
| | 0 | 180 | | } |
| | | 181 | | |
| | | 182 | | public override Func<IEnumerable<TElement>, TCollection> CreateImmutableEnumerableCreateRangeDelegate<TCollectio |
| | 0 | 183 | | CreateDelegate<Func<IEnumerable<TElement>, TCollection>>( |
| | 0 | 184 | | CreateImmutableEnumerableCreateRangeDelegate(typeof(TCollection), typeof(TElement), typeof(IEnumerable<T |
| | | 185 | | |
| | | 186 | | private static DynamicMethod CreateImmutableEnumerableCreateRangeDelegate(Type collectionType, Type elementType, |
| | 0 | 187 | | { |
| | 0 | 188 | | MethodInfo realMethod = collectionType.GetImmutableEnumerableCreateRangeMethod(elementType); |
| | | 189 | | |
| | 0 | 190 | | var dynamicMethod = new DynamicMethod( |
| | 0 | 191 | | realMethod.Name, |
| | 0 | 192 | | collectionType, |
| | 0 | 193 | | new[] { enumerableType }, |
| | 0 | 194 | | typeof(ReflectionEmitMemberAccessor).Module, |
| | 0 | 195 | | skipVisibility: true); |
| | | 196 | | |
| | 0 | 197 | | ILGenerator generator = dynamicMethod.GetILGenerator(); |
| | | 198 | | |
| | 0 | 199 | | generator.Emit(OpCodes.Ldarg_0); |
| | 0 | 200 | | generator.Emit(OpCodes.Call, realMethod); |
| | 0 | 201 | | generator.Emit(OpCodes.Ret); |
| | | 202 | | |
| | 0 | 203 | | return dynamicMethod; |
| | 0 | 204 | | } |
| | | 205 | | |
| | | 206 | | public override Func<IEnumerable<KeyValuePair<TKey, TValue>>, TCollection> CreateImmutableDictionaryCreateRangeD |
| | 0 | 207 | | CreateDelegate<Func<IEnumerable<KeyValuePair<TKey, TValue>>, TCollection>>( |
| | 0 | 208 | | CreateImmutableDictionaryCreateRangeDelegate(typeof(TCollection), typeof(TKey), typeof(TValue), typeof(I |
| | | 209 | | |
| | | 210 | | private static DynamicMethod CreateImmutableDictionaryCreateRangeDelegate(Type collectionType, Type keyType, Typ |
| | 0 | 211 | | { |
| | 0 | 212 | | MethodInfo realMethod = collectionType.GetImmutableDictionaryCreateRangeMethod(keyType, valueType); |
| | | 213 | | |
| | 0 | 214 | | var dynamicMethod = new DynamicMethod( |
| | 0 | 215 | | realMethod.Name, |
| | 0 | 216 | | collectionType, |
| | 0 | 217 | | new[] { enumerableType }, |
| | 0 | 218 | | typeof(ReflectionEmitMemberAccessor).Module, |
| | 0 | 219 | | skipVisibility: true); |
| | | 220 | | |
| | 0 | 221 | | ILGenerator generator = dynamicMethod.GetILGenerator(); |
| | | 222 | | |
| | 0 | 223 | | generator.Emit(OpCodes.Ldarg_0); |
| | 0 | 224 | | generator.Emit(OpCodes.Call, realMethod); |
| | 0 | 225 | | generator.Emit(OpCodes.Ret); |
| | | 226 | | |
| | 0 | 227 | | return dynamicMethod; |
| | 0 | 228 | | } |
| | | 229 | | |
| | | 230 | | public override Func<object, TProperty> CreatePropertyGetter<TProperty>(PropertyInfo propertyInfo) => |
| | 7716 | 231 | | CreateDelegate<Func<object, TProperty>>(CreatePropertyGetter(propertyInfo, typeof(TProperty))); |
| | | 232 | | |
| | | 233 | | private static DynamicMethod CreatePropertyGetter(PropertyInfo propertyInfo, Type runtimePropertyType) |
| | 7716 | 234 | | { |
| | 7716 | 235 | | MethodInfo? realMethod = propertyInfo.GetMethod; |
| | 7716 | 236 | | Debug.Assert(realMethod != null); |
| | | 237 | | |
| | 7716 | 238 | | Type? declaringType = propertyInfo.DeclaringType; |
| | 7716 | 239 | | Debug.Assert(declaringType != null); |
| | | 240 | | |
| | 7716 | 241 | | Type declaredPropertyType = propertyInfo.PropertyType; |
| | | 242 | | |
| | 7716 | 243 | | DynamicMethod dynamicMethod = CreateGetterMethod(propertyInfo.Name, runtimePropertyType); |
| | 7716 | 244 | | ILGenerator generator = dynamicMethod.GetILGenerator(); |
| | | 245 | | |
| | 7716 | 246 | | generator.Emit(OpCodes.Ldarg_0); |
| | | 247 | | |
| | 7716 | 248 | | if (declaringType.IsValueType) |
| | 0 | 249 | | { |
| | 0 | 250 | | generator.Emit(OpCodes.Unbox, declaringType); |
| | 0 | 251 | | generator.Emit(OpCodes.Call, realMethod); |
| | 0 | 252 | | } |
| | | 253 | | else |
| | 7716 | 254 | | { |
| | 7716 | 255 | | generator.Emit(OpCodes.Castclass, declaringType); |
| | 7716 | 256 | | generator.Emit(OpCodes.Callvirt, realMethod); |
| | 7716 | 257 | | } |
| | | 258 | | |
| | | 259 | | // declaredPropertyType: Type of the property |
| | | 260 | | // runtimePropertyType: <T> of JsonConverter / JsonPropertyInfo |
| | | 261 | | |
| | 7716 | 262 | | if (declaredPropertyType != runtimePropertyType && declaredPropertyType.IsValueType) |
| | 0 | 263 | | { |
| | | 264 | | // Not supported scenario: possible if declaredPropertyType == int? and runtimePropertyType == int |
| | | 265 | | // We should catch that particular case earlier in converter generation. |
| | 0 | 266 | | Debug.Assert(!runtimePropertyType.IsValueType); |
| | | 267 | | |
| | 0 | 268 | | generator.Emit(OpCodes.Box, declaredPropertyType); |
| | 0 | 269 | | } |
| | | 270 | | |
| | 7716 | 271 | | generator.Emit(OpCodes.Ret); |
| | | 272 | | |
| | 7716 | 273 | | return dynamicMethod; |
| | 7716 | 274 | | } |
| | | 275 | | |
| | | 276 | | public override Action<object, TProperty> CreatePropertySetter<TProperty>(PropertyInfo propertyInfo) => |
| | 7716 | 277 | | CreateDelegate<Action<object, TProperty>>(CreatePropertySetter(propertyInfo, typeof(TProperty))); |
| | | 278 | | |
| | | 279 | | private static DynamicMethod CreatePropertySetter(PropertyInfo propertyInfo, Type runtimePropertyType) |
| | 7716 | 280 | | { |
| | 7716 | 281 | | MethodInfo? realMethod = propertyInfo.SetMethod; |
| | 7716 | 282 | | Debug.Assert(realMethod != null); |
| | | 283 | | |
| | 7716 | 284 | | Type? declaringType = propertyInfo.DeclaringType; |
| | 7716 | 285 | | Debug.Assert(declaringType != null); |
| | | 286 | | |
| | 7716 | 287 | | Type declaredPropertyType = propertyInfo.PropertyType; |
| | | 288 | | |
| | 7716 | 289 | | DynamicMethod dynamicMethod = CreateSetterMethod(propertyInfo.Name, runtimePropertyType); |
| | 7716 | 290 | | ILGenerator generator = dynamicMethod.GetILGenerator(); |
| | | 291 | | |
| | 7716 | 292 | | generator.Emit(OpCodes.Ldarg_0); |
| | 7716 | 293 | | generator.Emit(declaringType.IsValueType ? OpCodes.Unbox : OpCodes.Castclass, declaringType); |
| | 7716 | 294 | | generator.Emit(OpCodes.Ldarg_1); |
| | | 295 | | |
| | | 296 | | // declaredPropertyType: Type of the property |
| | | 297 | | // runtimePropertyType: <T> of JsonConverter / JsonPropertyInfo |
| | | 298 | | |
| | 7716 | 299 | | if (declaredPropertyType != runtimePropertyType && declaredPropertyType.IsValueType) |
| | 0 | 300 | | { |
| | | 301 | | // Not supported scenario: possible if e.g. declaredPropertyType == int? and runtimePropertyType == int |
| | | 302 | | // We should catch that particular case earlier in converter generation. |
| | 0 | 303 | | Debug.Assert(!runtimePropertyType.IsValueType); |
| | | 304 | | |
| | 0 | 305 | | generator.Emit(OpCodes.Unbox_Any, declaredPropertyType); |
| | 0 | 306 | | } |
| | | 307 | | |
| | 7716 | 308 | | generator.Emit(declaringType.IsValueType ? OpCodes.Call : OpCodes.Callvirt, realMethod); |
| | 7716 | 309 | | generator.Emit(OpCodes.Ret); |
| | | 310 | | |
| | 7716 | 311 | | return dynamicMethod; |
| | 7716 | 312 | | } |
| | | 313 | | |
| | | 314 | | public override Func<object, TProperty> CreateFieldGetter<TProperty>(FieldInfo fieldInfo) => |
| | 0 | 315 | | CreateDelegate<Func<object, TProperty>>(CreateFieldGetter(fieldInfo, typeof(TProperty))); |
| | | 316 | | |
| | | 317 | | private static DynamicMethod CreateFieldGetter(FieldInfo fieldInfo, Type runtimeFieldType) |
| | 0 | 318 | | { |
| | 0 | 319 | | Type? declaringType = fieldInfo.DeclaringType; |
| | 0 | 320 | | Debug.Assert(declaringType != null); |
| | | 321 | | |
| | 0 | 322 | | Type declaredFieldType = fieldInfo.FieldType; |
| | | 323 | | |
| | 0 | 324 | | DynamicMethod dynamicMethod = CreateGetterMethod(fieldInfo.Name, runtimeFieldType); |
| | 0 | 325 | | ILGenerator generator = dynamicMethod.GetILGenerator(); |
| | | 326 | | |
| | 0 | 327 | | generator.Emit(OpCodes.Ldarg_0); |
| | 0 | 328 | | generator.Emit( |
| | 0 | 329 | | declaringType.IsValueType |
| | 0 | 330 | | ? OpCodes.Unbox |
| | 0 | 331 | | : OpCodes.Castclass, |
| | 0 | 332 | | declaringType); |
| | 0 | 333 | | generator.Emit(OpCodes.Ldfld, fieldInfo); |
| | | 334 | | |
| | | 335 | | // declaredFieldType: Type of the field |
| | | 336 | | // runtimeFieldType: <T> of JsonConverter / JsonPropertyInfo |
| | | 337 | | |
| | 0 | 338 | | if (declaredFieldType.IsValueType && declaredFieldType != runtimeFieldType) |
| | 0 | 339 | | { |
| | 0 | 340 | | generator.Emit(OpCodes.Box, declaredFieldType); |
| | 0 | 341 | | } |
| | | 342 | | |
| | 0 | 343 | | generator.Emit(OpCodes.Ret); |
| | | 344 | | |
| | 0 | 345 | | return dynamicMethod; |
| | 0 | 346 | | } |
| | | 347 | | |
| | | 348 | | public override Action<object, TProperty> CreateFieldSetter<TProperty>(FieldInfo fieldInfo) => |
| | 0 | 349 | | CreateDelegate<Action<object, TProperty>>(CreateFieldSetter(fieldInfo, typeof(TProperty))); |
| | | 350 | | |
| | | 351 | | private static DynamicMethod CreateFieldSetter(FieldInfo fieldInfo, Type runtimeFieldType) |
| | 0 | 352 | | { |
| | 0 | 353 | | Type? declaringType = fieldInfo.DeclaringType; |
| | 0 | 354 | | Debug.Assert(declaringType != null); |
| | | 355 | | |
| | 0 | 356 | | Type declaredFieldType = fieldInfo.FieldType; |
| | | 357 | | |
| | 0 | 358 | | DynamicMethod dynamicMethod = CreateSetterMethod(fieldInfo.Name, runtimeFieldType); |
| | 0 | 359 | | ILGenerator generator = dynamicMethod.GetILGenerator(); |
| | | 360 | | |
| | 0 | 361 | | generator.Emit(OpCodes.Ldarg_0); |
| | 0 | 362 | | generator.Emit(declaringType.IsValueType ? OpCodes.Unbox : OpCodes.Castclass, declaringType); |
| | 0 | 363 | | generator.Emit(OpCodes.Ldarg_1); |
| | | 364 | | |
| | | 365 | | // declaredFieldType: Type of the field |
| | | 366 | | // runtimeFieldType: <T> of JsonConverter / JsonPropertyInfo |
| | | 367 | | |
| | 0 | 368 | | if (declaredFieldType != runtimeFieldType && declaredFieldType.IsValueType) |
| | 0 | 369 | | { |
| | 0 | 370 | | generator.Emit(OpCodes.Unbox_Any, declaredFieldType); |
| | 0 | 371 | | } |
| | | 372 | | |
| | 0 | 373 | | generator.Emit(OpCodes.Stfld, fieldInfo); |
| | 0 | 374 | | generator.Emit(OpCodes.Ret); |
| | | 375 | | |
| | 0 | 376 | | return dynamicMethod; |
| | 0 | 377 | | } |
| | | 378 | | |
| | | 379 | | private static DynamicMethod CreateGetterMethod(string memberName, Type memberType) => |
| | 7716 | 380 | | new DynamicMethod( |
| | 7716 | 381 | | memberName + "Getter", |
| | 7716 | 382 | | memberType, |
| | 7716 | 383 | | new[] { JsonTypeInfo.ObjectType }, |
| | 7716 | 384 | | typeof(ReflectionEmitMemberAccessor).Module, |
| | 7716 | 385 | | skipVisibility: true); |
| | | 386 | | |
| | | 387 | | private static DynamicMethod CreateSetterMethod(string memberName, Type memberType) => |
| | 7716 | 388 | | new DynamicMethod( |
| | 7716 | 389 | | memberName + "Setter", |
| | 7716 | 390 | | typeof(void), |
| | 7716 | 391 | | new[] { JsonTypeInfo.ObjectType, memberType }, |
| | 7716 | 392 | | typeof(ReflectionEmitMemberAccessor).Module, |
| | 7716 | 393 | | skipVisibility: true); |
| | | 394 | | |
| | | 395 | | [return: NotNullIfNotNull(nameof(method))] |
| | | 396 | | private static T? CreateDelegate<T>(DynamicMethod? method) where T : Delegate => |
| | 18427 | 397 | | (T?)method?.CreateDelegate(typeof(T)); |
| | | 398 | | } |
| | | 399 | | } |
| | | 400 | | #endif |