Example #1
0
            static JsonTypeInfo CreateJsonTypeInfo(Type type, JsonSerializerOptions options)
            {
                JsonTypeInfo.ValidateType(type, null, null, options);

                MethodInfo methodInfo = typeof(JsonSerializerOptions).GetMethod(nameof(CreateReflectionJsonTypeInfo), BindingFlags.NonPublic | BindingFlags.Instance) !;

#if NETCOREAPP
                return((JsonTypeInfo)methodInfo.MakeGenericMethod(type).Invoke(options, BindingFlags.NonPublic | BindingFlags.DoNotWrapExceptions, null, null, null) !);
#else
                try
                {
                    return((JsonTypeInfo)methodInfo.MakeGenericMethod(type).Invoke(options, null) !);
                }
                catch (TargetInvocationException ex)
                {
                    // Some of the validation is done during construction (i.e. validity of JsonConverter, inner types etc.)
                    // therefore we need to unwrap TargetInvocationException for better user experience
                    ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
                    throw null !;
                }
#endif
            }