示例#1
0
        public static string ConvertToJson(PMap map, SettingSchema schema, SettingWriterOptions options)
        {
            SettingWriter writer = new SettingWriter(schema, options);

            writer.Visit(map);

            // End files with a newline character.
            writer.outputBuilder.AppendLine();
            return(writer.outputBuilder.ToString());
        }
示例#2
0
        /// <summary>
        /// Generates the text to save to the setting file from the current values in <paramref name="settings"/>.
        /// </summary>
        /// <param name="settings">
        /// The settings to write.
        /// </param>
        /// <param name="options">
        /// Specifies options for writing the settings.
        /// </param>
        /// <returns>
        /// The text to save.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="settings"/> is null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="settings"/> has an unexpected schema.
        /// </exception>
        public string GenerateJson(SettingObject settings, SettingWriterOptions options)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            if (settings.Schema != TemplateSettings.Schema)
            {
                throw new ArgumentException(
                          $"{nameof(settings)} has an unexpected schema",
                          nameof(settings));
            }

            return(SettingWriter.ConvertToJson(
                       settings.Map,
                       schema: settings.Schema,
                       options: options));
        }