ObsoleteAttribute.cs 1.7 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: Attribute for functions, etc that will be removed.
  9. **
  10. **
  11. ===========================================================*/
  12. namespace System
  13. {
  14. // This attribute is attached to members that are not to be used any longer.
  15. // Message is some human readable explanation of what to use
  16. // Error indicates if the compiler should treat usage of such a method as an
  17. // error. (this would be used if the actual implementation of the obsolete
  18. // method's implementation had changed).
  19. //
  20. [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum |
  21. AttributeTargets.Interface | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Delegate,
  22. Inherited = false)]
  23. public sealed class ObsoleteAttribute : Attribute
  24. {
  25. private readonly string? _message;
  26. private readonly bool _error;
  27. public ObsoleteAttribute()
  28. {
  29. _message = null;
  30. _error = false;
  31. }
  32. public ObsoleteAttribute(string? message)
  33. {
  34. _message = message;
  35. _error = false;
  36. }
  37. public ObsoleteAttribute(string? message, bool error)
  38. {
  39. _message = message;
  40. _error = error;
  41. }
  42. public string? Message => _message;
  43. public bool IsError => _error;
  44. }
  45. }