/// <summary> /// Initializes a new instance of a <see cref="SettingSchema"/>. /// </summary> /// <param name="properties"> /// The set of properties with unique keys to support. /// </param> /// <param name="description"> /// The built-in description of the schema in a settings file. /// </param> /// <exception cref="ArgumentException"> /// Two or more properties have the same key; or one of the properties is null. /// </exception> public SettingSchema(IEnumerable <SettingProperty> properties, SettingComment description = null) { this.properties = properties != null && properties.Any() ? new Dictionary <string, SettingProperty>() : emptyProperties; if (properties != null) { foreach (var property in properties) { if (property == null) { throw new ArgumentException("One of the properties is null.", nameof(properties)); } this.properties.Add(property.Name.Key, property); } } Description = description; }
private void AppendCommentLines(SettingComment comment) { if (comment != null) { // Available width for comments depends on the current indent level. // Decrease by an extra 1 because of the space between '//' and the text. int availableCommentWidth = maxLineLength - currentDepth * Indentation - JsonSpecialCharacter.SingleLineCommentStart.Length - 1; bool first = true; foreach (var paragraph in comment.Paragraphs) { if (!first) { // Extra line with empty single line comment to separate paragraphs. AppendIndent(); outputBuilder.Append(JsonSpecialCharacter.SingleLineCommentStart); outputBuilder.AppendLine(); } else { first = false; } foreach (string commentLine in GetCommentLines(paragraph, availableCommentWidth)) { AppendIndent(); outputBuilder.Append(JsonSpecialCharacter.SingleLineCommentStart); outputBuilder.Append(SpaceChar); outputBuilder.Append(commentLine); outputBuilder.AppendLine(); } } } }
/// <summary> /// Initializes a new instance of a <see cref="SettingSchema"/>. /// </summary> /// <param name="description"> /// The built-in description of the schema in a settings file. /// </param> /// <param name="properties"> /// The set of properties with unique keys to support. /// </param> /// <exception cref="ArgumentException"> /// Two or more properties have the same key. /// </exception> public SettingSchema(SettingComment description, params SettingProperty[] properties) : this(properties, description) { }
/// <summary> /// Initializes a new instance of <see cref="SettingProperty"/>. /// </summary> /// <param name="name"> /// The name of the property. /// </param> /// <param name="description"> /// The built-in description of the property in a settings file. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="name"/> is null. /// </exception> public SettingProperty(SettingKey name, SettingComment description) { Name = name ?? throw new ArgumentNullException(nameof(name)); Description = description; }