Beispiel #1
0
        public SettingWriter(SettingSchema schema, SettingWriterOptions options)
        {
            this.schema  = schema;
            this.options = options;

            // Write schema description, if any.
            AppendCommentLines(schema.Description);
        }
Beispiel #2
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());
        }
Beispiel #3
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));
        }
Beispiel #4
0
 /// <summary>
 /// Attempts to overwrite the setting file with 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>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="settings"/> is null.
 /// </exception>
 /// <exception cref="ArgumentException">
 /// <paramref name="settings"/> has an unexpected schema.
 /// </exception>
 public void WriteToFile(SettingObject settings, SettingWriterOptions options)
 => Save(GenerateJson(settings, options));