private static JObject SerializeOption(IConfigurationOptionDescriptor o)
        {
            var optionRoot = new JObject
            {
                { nameof(o.Default), JToken.FromObject(o.Default) },
                { nameof(o.DisplayName), o.DisplayName != string.Empty ? o.DisplayName : o.OptionKey },
                { nameof(o.Description), o.Description },
                { nameof(o.Simple), o.Simple },
                { nameof(o.CustomMetadata), JToken.FromObject(o.CustomMetadata) },
                { nameof(Type), ConfigurationCollectionSerializer.GetTypeString(o) },
            };

            if (o.Type == typeof(int))
            {
                optionRoot.Add(nameof(o.Min), (int)o.Min);
                optionRoot.Add(nameof(o.Max), (int)o.Max);
                optionRoot.Add(nameof(o.Increment), (int)o.Increment);
            }

            if (o.Type == typeof(double))
            {
                optionRoot.Add(nameof(o.Min), o.Min);
                optionRoot.Add(nameof(o.Max), o.Max);
                optionRoot.Add(nameof(o.Increment), o.Increment);
            }

            return(optionRoot);
        }
        /// <inheritdoc/>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            IConfigurationCollection collection = (IConfigurationCollection)value;
            JObject collectionRoot = new JObject();

            foreach (var section in collection.Select(s => s.Value))
            {
                JObject sectionOptionsRoot = new JObject();
                foreach (var option in section)
                {
                    JObject optionRoot = new JObject()
                    {
                        { "Value", JObject.FromObject(option.Value) },
                        { "Descriptor", ConfigurationCollectionSerializer.SerializeOption(option.Key) },
                    };
                    if (option.Key.Type.GetTypeInfo().IsEnum)
                    {
                        optionRoot.Add("Selection",
                                       new JObject(ConfigurationCollectionSerializer.SerializeEnumValues(option.Key.Type)));
                    }

                    sectionOptionsRoot.Add(option.Key.OptionKey, optionRoot);
                }

                JObject sectionRoot = new JObject
                {
                    { "Configuration", sectionOptionsRoot },
                    { "Descriptor", ConfigurationCollectionSerializer.SerializeSectionDescriptor(section.Descriptor) },
                };

                collectionRoot.Add(section.Descriptor.SectionName, sectionRoot);
            }

            collectionRoot.WriteTo(writer, new StringEnumConverter());
        }