Beispiel #1
0
        /// <summary>
        /// Creates serialization metadata for an object.
        /// </summary>
        public JsonTypeInfoInternal(JsonSerializerOptions options, JsonObjectInfoValues <T> objectInfo) : base(typeof(T), options)
        {
#pragma warning disable CS8714
            // The type cannot be used as type parameter in the generic type or method.
            // Nullability of type argument doesn't match 'notnull' constraint.
            JsonConverter converter;

            if (objectInfo.ObjectWithParameterizedConstructorCreator != null)
            {
                converter = new JsonMetadataServicesConverter <T>(
                    () => new LargeObjectWithParameterizedConstructorConverter <T>(),
                    ConverterStrategy.Object);
                CreateObjectWithArgs = objectInfo.ObjectWithParameterizedConstructorCreator;
                CtorParamInitFunc    = objectInfo.ConstructorParameterMetadataInitializer;
            }
            else
            {
                converter = new JsonMetadataServicesConverter <T>(() => new ObjectDefaultConverter <T>(), ConverterStrategy.Object);
                SetCreateObjectFunc(objectInfo.ObjectCreator);
            }
#pragma warning restore CS8714

            PropInitFunc            = objectInfo.PropertyMetadataInitializer;
            SerializeHandler        = objectInfo.SerializeHandler;
            PropertyInfoForTypeInfo = JsonMetadataServices.CreateJsonPropertyInfoForClassInfo(typeof(T), this, converter, Options);
            NumberHandling          = objectInfo.NumberHandling;
        }
Beispiel #2
0
        private static JsonConverter GetConverter(JsonObjectInfoValues <T> objectInfo)
        {
#pragma warning disable CS8714
            // The type cannot be used as type parameter in the generic type or method.
            // Nullability of type argument doesn't match 'notnull' constraint.
            if (objectInfo.ObjectWithParameterizedConstructorCreator != null)
            {
                return(new JsonMetadataServicesConverter <T>(
                           () => new LargeObjectWithParameterizedConstructorConverter <T>(),
                           ConverterStrategy.Object));
            }
            else
            {
                return(new JsonMetadataServicesConverter <T>(() => new ObjectDefaultConverter <T>(), ConverterStrategy.Object));
            }
#pragma warning restore CS8714
        }
Beispiel #3
0
        /// <summary>
        /// Creates serialization metadata for an object.
        /// </summary>
        public SourceGenJsonTypeInfo(JsonSerializerOptions options, JsonObjectInfoValues <T> objectInfo) : base(GetConverter(objectInfo), options)
        {
            if (objectInfo.ObjectWithParameterizedConstructorCreator != null)
            {
                CreateObjectWithArgs = objectInfo.ObjectWithParameterizedConstructorCreator;
                CtorParamInitFunc    = objectInfo.ConstructorParameterMetadataInitializer;
            }
            else
            {
                SetCreateObjectFunc(objectInfo.ObjectCreator);
            }


            PropInitFunc     = objectInfo.PropertyMetadataInitializer;
            SerializeHandler = objectInfo.SerializeHandler;
            NumberHandling   = objectInfo.NumberHandling;
        }
Beispiel #4
0
        /// <summary>
        /// Creates serialization metadata for an object.
        /// </summary>
        public SourceGenJsonTypeInfo(JsonSerializerOptions options, JsonObjectInfoValues <T> objectInfo) : base(GetConverter(objectInfo), options)
        {
            if (objectInfo.ObjectWithParameterizedConstructorCreator != null)
            {
                CreateObjectWithArgs = objectInfo.ObjectWithParameterizedConstructorCreator;
                CtorParamInitFunc    = objectInfo.ConstructorParameterMetadataInitializer;
            }
            else
            {
                SetCreateObjectIfCompatible(objectInfo.ObjectCreator);
                CreateObjectForExtensionDataProperty = ((JsonTypeInfo)this).CreateObject;
            }

            PropInitFunc     = objectInfo.PropertyMetadataInitializer;
            SerializeHandler = objectInfo.SerializeHandler;
            NumberHandling   = objectInfo.NumberHandling;
            PopulatePolymorphismMetadata();
            MapInterfaceTypesToCallbacks();

            // Plug in any converter configuration -- should be run last.
            Converter.ConfigureJsonTypeInfo(this, options);
        }
Beispiel #5
0
        /// <summary>
        /// Creates metadata for a complex class or struct.
        /// </summary>
        /// <param name="options">The <see cref="JsonSerializerOptions"/> to initialize the metadata with.</param>
        /// <param name="objectInfo">Provides serialization metadata about an object type with constructors, properties, and fields.</param>
        /// <typeparam name="T">The type of the class or struct.</typeparam>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="options"/> or <paramref name="objectInfo"/> is null.</exception>
        /// <returns>A <see cref="JsonTypeInfo{T}"/> instance representing the class or struct.</returns>
        /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called directly.</remarks>
        public static JsonTypeInfo <T> CreateObjectInfo <T>(JsonSerializerOptions options, JsonObjectInfoValues <T> objectInfo) where T : notnull
        {
            if (options is null)
            {
                ThrowHelper.ThrowArgumentNullException(nameof(options));
            }
            if (objectInfo is null)
            {
                ThrowHelper.ThrowArgumentNullException(nameof(objectInfo));
            }

            return(new SourceGenJsonTypeInfo <T>(options, objectInfo));
        }
Beispiel #6
0
 /// <summary>
 /// Creates metadata for a complex class or struct.
 /// </summary>
 /// <param name="options">The <see cref="JsonSerializerOptions"/> to initialize the metadata with.</param>
 /// <param name="objectInfo">Provides serialization metadata about an object type with constructors, properties, and fields.</param>
 /// <typeparam name="T">The type of the class or struct.</typeparam>
 /// <exception cref="ArgumentNullException">Thrown when <paramref name="options"/> or <paramref name="objectInfo"/> is null.</exception>
 /// <returns>A <see cref="JsonTypeInfo{T}"/> instance representing the class or struct.</returns>
 /// <remarks>This API is for use by the output of the System.Text.Json source generator and should not be called directly.</remarks>
 public static JsonTypeInfo <T> CreateObjectInfo <T>(JsonSerializerOptions options, JsonObjectInfoValues <T> objectInfo) where T : notnull
 => new JsonTypeInfoInternal <T>(