Marks program elements that are no longer in use.
public ref class ObsoleteAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Delegate | System.AttributeTargets.Enum | System.AttributeTargets.Event | System.AttributeTargets.Field | System.AttributeTargets.Interface | System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Struct, Inherited=false)]
public sealed class ObsoleteAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Delegate | System.AttributeTargets.Enum | System.AttributeTargets.Event | System.AttributeTargets.Field | System.AttributeTargets.Interface | System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Struct, Inherited=false)]
[System.Serializable]
public sealed class ObsoleteAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Delegate | System.AttributeTargets.Enum | System.AttributeTargets.Event | System.AttributeTargets.Field | System.AttributeTargets.Interface | System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Struct, Inherited=false)]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class ObsoleteAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Delegate | System.AttributeTargets.Enum | System.AttributeTargets.Event | System.AttributeTargets.Field | System.AttributeTargets.Interface | System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Struct, Inherited=false)>]
type ObsoleteAttribute = class
inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Delegate | System.AttributeTargets.Enum | System.AttributeTargets.Event | System.AttributeTargets.Field | System.AttributeTargets.Interface | System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Struct, Inherited=false)>]
[<System.Serializable>]
type ObsoleteAttribute = class
inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Delegate | System.AttributeTargets.Enum | System.AttributeTargets.Event | System.AttributeTargets.Field | System.AttributeTargets.Interface | System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Struct, Inherited=false)>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type ObsoleteAttribute = class
inherit Attribute
Public NotInheritable Class ObsoleteAttribute
Inherits Attribute
The following example defines a class that contains a property and a method that are marked with the ObsoleteAttribute attribute. Accessing the value of the OldProperty
property in code generates a compiler warning, but calling the CallOldMethod
method generates a compiler error. The example also shows the output that results when you attempt to compile the source code.
using System;
using System.Reflection;
public class Example
{
// Mark OldProperty As Obsolete.
[ObsoleteAttribute("This property is obsolete. Use NewProperty instead.", false)]
public static string OldProperty
{ get { return "The old property value."; } }
public static string NewProperty
{ get { return "The new property value."; } }
// Mark CallOldMethod As Obsolete.
[ObsoleteAttribute("This method is obsolete. Call CallNewMethod instead.", true)]
public static string CallOldMethod()
{
return "You have called CallOldMethod.";
}
public static string CallNewMethod()
{
return "You have called CallNewMethod.";
}
public static void Main()
{
Console.WriteLine(OldProperty);
Console.WriteLine();
Console.WriteLine(CallOldMethod());
}
}
// The attempt to compile this example produces output like the following output:
// Example.cs(31,25): error CS0619: 'Example.CallOldMethod()' is obsolete:
// 'This method is obsolete. Call CallNewMethod instead.'
// Example.cs(29,25): warning CS0618: 'Example.OldProperty' is obsolete:
// 'This property is obsolete. Use NewProperty instead.'
open System
// Mark oldValue As Obsolete.
[<ObsoleteAttribute("This value is obsolete. Use newValue instead.", false)>]
let oldValue =
"The old property value."
let newValue =
"The new property value."
// Mark callOldFunction As Obsolete.
[<ObsoleteAttribute("This function is obsolete. Call callNewFunction instead.", true)>]
let callOldFunction () =
"You have called CallOldMethod."
let callNewFunction () =
"You have called CallNewMethod."
printfn $"{oldValue}"
printfn ""
printfn $"{callOldFunction ()}"
// The attempt to compile this example produces output like the following output:
// Example.fs(23,12): error FS0101: This construct is deprecated. This function is obsolete. Call callNewFunction instead.
// Example.fs(21,12): warning FS0044: This construct is deprecated. This value is obsolete. Use newValue instead.
Imports System.Reflection
Public Module Example
' Mark OldProperty As Obsolete.
<ObsoleteAttribute("This property is obsolete. Use NewProperty instead.", False)>
Public ReadOnly Property OldProperty As String
Get
Return "The old property value."
End Get
End Property
Public ReadOnly Property NewProperty As String
Get
Return "The new property value."
End Get
End Property
' Mark OldMethod As Obsolete.
<ObsoleteAttribute("This method is obsolete. Call CallNewMethod instead.", True)>
Public Function CallOldMethod() As String
Return "You have called CallOldMethod."
End Function
Public Function CallNewMethod() As String
Return "You have called NewMethod."
End Function
Public Sub Main()
Console.WriteLine(OldProperty)
Console.WriteLine()
Console.WriteLine(CallOldMethod())
End Sub
End Module
' The attempt to compile this example produces output like the following:
' Example.vb(30) : warning BC40000: 'Public ReadOnly Property OldProperty As String' is obsolete:
' 'This property is obsolete. Use NewProperty instead.'.
'
' Console.WriteLine(OldProperty)
' ~~~~~~~~~~~
' Example.vb(32) : error BC30668: 'Public Function CallOldMethod() As String' is obsolete:
' 'This method is obsolete. Call CallNewMethod instead.'.
'
' Console.WriteLine(CallOldMethod())
' ~~~~~~~~~~~~~
Source code imported from ObsoleteAttribute.cs without any changes, all resulting warnings ignored accordingly.
Constructors Properties DiagnosticIdGets or sets the ID that the compiler will use when reporting a use of the API.
IsErrorGets a value that indicates whether the compiler will treat usage of the obsolete program element as an error.
MessageGets the workaround message.
TypeIdWhen implemented in a derived class, gets a unique identifier for this Attribute.
(Inherited from Attribute) UrlFormatGets or sets the URL for corresponding documentation. The API accepts a format string instead of an actual URL, creating a generic URL that includes the diagnostic ID.
Methods Explicit Interface Implementations _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)Maps a set of names to a corresponding set of dispatch identifiers.
(Inherited from Attribute) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)Retrieves the type information for an object, which can be used to get the type information for an interface.
(Inherited from Attribute) _Attribute.GetTypeInfoCount(UInt32)Retrieves the number of type information interfaces that an object provides (either 0 or 1).
(Inherited from Attribute) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)Provides access to properties and methods exposed by an object.
(Inherited from Attribute) See alsoRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4