SettingDefinitionGroup.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.Immutable;
  4. using Abp.Localization;
  5. namespace Abp.Configuration
  6. {
  7. /// <summary>
  8. /// A setting group is used to group some settings togehter.
  9. /// A group can be child of another group and can have child groups.
  10. /// </summary>
  11. public class SettingDefinitionGroup
  12. {
  13. /// <summary>
  14. /// Unique name of the setting group.
  15. /// </summary>
  16. public string Name { get; private set; }
  17. /// <summary>
  18. /// Display name of the setting.
  19. /// This can be used to show setting to the user.
  20. /// </summary>
  21. public ILocalizableString DisplayName { get; private set; }
  22. /// <summary>
  23. /// Gets parent of this group.
  24. /// </summary>
  25. public SettingDefinitionGroup Parent { get; private set; }
  26. /// <summary>
  27. /// Gets a list of all children of this group.
  28. /// </summary>
  29. public IReadOnlyList<SettingDefinitionGroup> Children
  30. {
  31. get { return _children.ToImmutableList(); }
  32. }
  33. private readonly List<SettingDefinitionGroup> _children;
  34. /// <summary>
  35. /// Creates a new <see cref="SettingDefinitionGroup"/> object.
  36. /// </summary>
  37. /// <param name="name">Unique name of the setting group</param>
  38. /// <param name="displayName">Display name of the setting</param>
  39. public SettingDefinitionGroup(string name, ILocalizableString displayName)
  40. {
  41. Check.NotNullOrWhiteSpace(name, nameof(name));
  42. Name = name;
  43. DisplayName = displayName;
  44. _children = new List<SettingDefinitionGroup>();
  45. }
  46. /// <summary>
  47. /// Adds a <see cref="SettingDefinitionGroup"/> as child of this group.
  48. /// </summary>
  49. /// <param name="child">Child to be added</param>
  50. /// <returns>This child group to be able to add more child</returns>
  51. public SettingDefinitionGroup AddChild(SettingDefinitionGroup child)
  52. {
  53. if (child.Parent != null)
  54. {
  55. throw new AbpException("Setting group " + child.Name + " has already a Parent (" + child.Parent.Name + ").");
  56. }
  57. _children.Add(child);
  58. child.Parent = this;
  59. return this;
  60. }
  61. }
  62. }