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); }
private static string GetTypeString(IConfigurationOptionDescriptor o) { if (o.Type == typeof(int)) { return("integer"); } if (o.Type == typeof(bool)) { return("boolean"); } if (o.Type == typeof(double)) { return("decimal"); } if (o.Type.GetTypeInfo().IsEnum) { return("selection"); } if (o.IsPath) { return("path"); } return("string"); }