FeatureDictionary.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. namespace Abp.Application.Features
  4. {
  5. /// <summary>
  6. /// Used to store <see cref="Feature"/>s.
  7. /// </summary>
  8. public class FeatureDictionary : Dictionary<string, Feature>
  9. {
  10. /// <summary>
  11. /// Adds all the child features of the current features, recursively.
  12. /// </summary>
  13. public void AddAllFeatures()
  14. {
  15. foreach (var feature in Values.ToList())
  16. {
  17. AddFeatureRecursively(feature);
  18. }
  19. }
  20. private void AddFeatureRecursively(Feature feature)
  21. {
  22. //Prevent multiple additions of the same-named feature.
  23. if (TryGetValue(feature.Name, out var existingFeature))
  24. {
  25. if (existingFeature != feature)
  26. {
  27. throw new AbpInitializationException("Duplicate feature name detected for " + feature.Name);
  28. }
  29. }
  30. else
  31. {
  32. this[feature.Name] = feature;
  33. }
  34. //Add child features (recursive call)
  35. foreach (var childFeature in feature.Children)
  36. {
  37. AddFeatureRecursively(childFeature);
  38. }
  39. }
  40. }
  41. }