AttributeUsageAttribute.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. /*============================================================
  5. **
  6. **
  7. **
  8. ** Purpose: The class denotes how to specify the usage of an attribute
  9. **
  10. **
  11. ===========================================================*/
  12. namespace System
  13. {
  14. /* By default, attributes are inherited and multiple attributes are not allowed */
  15. [AttributeUsage(AttributeTargets.Class, Inherited = true)]
  16. public sealed class AttributeUsageAttribute : Attribute
  17. {
  18. private readonly AttributeTargets _attributeTarget; // Defaults to all
  19. private bool _allowMultiple = false; // Defaults to false
  20. private bool _inherited = true; // Defaults to true
  21. internal static readonly AttributeUsageAttribute Default = new AttributeUsageAttribute(AttributeTargets.All);
  22. public AttributeUsageAttribute(AttributeTargets validOn)
  23. {
  24. _attributeTarget = validOn;
  25. }
  26. internal AttributeUsageAttribute(AttributeTargets validOn, bool allowMultiple, bool inherited)
  27. {
  28. _attributeTarget = validOn;
  29. _allowMultiple = allowMultiple;
  30. _inherited = inherited;
  31. }
  32. public AttributeTargets ValidOn => _attributeTarget;
  33. public bool AllowMultiple
  34. {
  35. get => _allowMultiple;
  36. set => _allowMultiple = value;
  37. }
  38. public bool Inherited
  39. {
  40. get => _inherited;
  41. set => _inherited = value;
  42. }
  43. }
  44. }