AttributeUsageAttribute.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. using System.Reflection;
  13. namespace System
  14. {
  15. /* By default, attributes are inherited and multiple attributes are not allowed */
  16. [AttributeUsage(AttributeTargets.Class, Inherited = true)]
  17. public sealed class AttributeUsageAttribute : Attribute
  18. {
  19. private AttributeTargets _attributeTarget = AttributeTargets.All; // Defaults to all
  20. private bool _allowMultiple = false; // Defaults to false
  21. private bool _inherited = true; // Defaults to true
  22. internal static readonly AttributeUsageAttribute Default = new AttributeUsageAttribute(AttributeTargets.All);
  23. //Constructors
  24. public AttributeUsageAttribute(AttributeTargets validOn)
  25. {
  26. _attributeTarget = validOn;
  27. }
  28. internal AttributeUsageAttribute(AttributeTargets validOn, bool allowMultiple, bool inherited)
  29. {
  30. _attributeTarget = validOn;
  31. _allowMultiple = allowMultiple;
  32. _inherited = inherited;
  33. }
  34. public AttributeTargets ValidOn
  35. {
  36. get { return _attributeTarget; }
  37. }
  38. public bool AllowMultiple
  39. {
  40. get { return _allowMultiple; }
  41. set { _allowMultiple = value; }
  42. }
  43. public bool Inherited
  44. {
  45. get { return _inherited; }
  46. set { _inherited = value; }
  47. }
  48. }
  49. }