SettingDefinition.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System;
  2. using Abp.Localization;
  3. namespace Abp.Configuration
  4. {
  5. /// <summary>
  6. /// Defines a setting.
  7. /// A setting is used to configure and change behavior of the application.
  8. /// </summary>
  9. public class SettingDefinition
  10. {
  11. /// <summary>
  12. /// Unique name of the setting.
  13. /// </summary>
  14. public string Name { get; private set; }
  15. /// <summary>
  16. /// Display name of the setting.
  17. /// This can be used to show setting to the user.
  18. /// </summary>
  19. public ILocalizableString DisplayName { get; set; }
  20. /// <summary>
  21. /// A brief description for this setting.
  22. /// </summary>
  23. public ILocalizableString Description { get; set; }
  24. /// <summary>
  25. /// Scopes of this setting.
  26. /// Default value: <see cref="SettingScopes.Application"/>.
  27. /// </summary>
  28. public SettingScopes Scopes { get; set; }
  29. /// <summary>
  30. /// Is this setting inherited from parent scopes.
  31. /// Default: True.
  32. /// </summary>
  33. public bool IsInherited { get; set; }
  34. /// <summary>
  35. /// Gets/sets group for this setting.
  36. /// </summary>
  37. public SettingDefinitionGroup Group { get; set; }
  38. /// <summary>
  39. /// Default value of the setting.
  40. /// </summary>
  41. public string DefaultValue { get; set; }
  42. /// <summary>
  43. /// Can clients see this setting and it's value.
  44. /// It maybe dangerous for some settings to be visible to clients (such as email server password).
  45. /// Default: false.
  46. /// </summary>
  47. [Obsolete("Use ClientVisibilityProvider instead.")]
  48. public bool IsVisibleToClients { get; set; }
  49. /// <summary>
  50. /// Client visibility definition for the setting.
  51. /// </summary>
  52. public ISettingClientVisibilityProvider ClientVisibilityProvider { get; set; }
  53. /// <summary>
  54. /// Can be used to store a custom object related to this setting.
  55. /// </summary>
  56. public object CustomData { get; set; }
  57. /// <summary>
  58. /// Creates a new <see cref="SettingDefinition"/> object.
  59. /// </summary>
  60. /// <param name="name">Unique name of the setting</param>
  61. /// <param name="defaultValue">Default value of the setting</param>
  62. /// <param name="displayName">Display name of the permission</param>
  63. /// <param name="group">Group of this setting</param>
  64. /// <param name="description">A brief description for this setting</param>
  65. /// <param name="scopes">Scopes of this setting. Default value: <see cref="SettingScopes.Application"/>.</param>
  66. /// <param name="isVisibleToClients">Can clients see this setting and it's value. Default: false</param>
  67. /// <param name="isInherited">Is this setting inherited from parent scopes. Default: True.</param>
  68. /// <param name="customData">Can be used to store a custom object related to this setting</param>
  69. /// <param name="clientVisibilityProvider">Client visibility definition for the setting. Default: invisible</param>
  70. public SettingDefinition(
  71. string name,
  72. string defaultValue,
  73. ILocalizableString displayName = null,
  74. SettingDefinitionGroup group = null,
  75. ILocalizableString description = null,
  76. SettingScopes scopes = SettingScopes.Application,
  77. bool isVisibleToClients = false,
  78. bool isInherited = true,
  79. object customData = null,
  80. ISettingClientVisibilityProvider clientVisibilityProvider = null)
  81. {
  82. if (string.IsNullOrEmpty(name))
  83. {
  84. throw new ArgumentNullException(nameof(name));
  85. }
  86. Name = name;
  87. DefaultValue = defaultValue;
  88. DisplayName = displayName;
  89. Group = @group;
  90. Description = description;
  91. Scopes = scopes;
  92. IsVisibleToClients = isVisibleToClients;
  93. IsInherited = isInherited;
  94. CustomData = customData;
  95. ClientVisibilityProvider = new HiddenSettingClientVisibilityProvider();
  96. if (isVisibleToClients)
  97. {
  98. ClientVisibilityProvider = new VisibleSettingClientVisibilityProvider();
  99. }
  100. else if (clientVisibilityProvider != null)
  101. {
  102. ClientVisibilityProvider = clientVisibilityProvider;
  103. }
  104. }
  105. }
  106. }