ObsoleteAttribute 클래스

정의

더 이상 사용하지 않는 프로그램 요소를 표시합니다. 이 클래스는 상속될 수 없습니다.

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
상속
ObsoleteAttribute
특성

예제

다음 예제에서는 속성을 포함하는 클래스와 특성으로 표시된 메서드를 ObsoleteAttribute 정의합니다. 코드에서 속성 값에 OldProperty 액세스하면 컴파일러 경고가 생성되지만 메서드를 CallOldMethod 호출하면 컴파일러 오류가 발생합니다. 이 예제에서는 소스 코드를 컴파일하려고 할 때 발생하는 출력도 보여줍니다.

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())
'                            ~~~~~~~~~~~~~

설명

ObsoleteAttribute 는 어셈블리, 모듈, 매개 변수 및 반환 값을 제외한 모든 프로그램 요소에 적용할 수 있습니다. 요소를 더 이상 사용되지 않음으로 표시하면 이후 버전의 제품에서 요소가 제거될 수 있음을 사용자에게 알릴 수 있습니다.

속성에 Message 할당된 문자열은 코드에서 특성 대상이 사용될 때 컴파일러에서 내보냅니다. 이상적으로 문자열은 몇 가지 해결 방법 또는 프로그래밍 방식의 대안을 제공해야 합니다.

사용 된 IsError 특성을 사용 하 여 ObsoleteAttribute 오류를 내보내야 하는지 여부를 컴파일러에 표시 하는 속성 (IsErrortrue) 또는 경고 (IsErrorfalse).

특성을 사용 하는 방법에 대 한 자세한 내용은 참조 하세요. 특성합니다.

생성자

ObsoleteAttribute()

기본 속성을 사용하여 ObsoleteAttribute 클래스의 새 인스턴스를 초기화합니다.

ObsoleteAttribute(String)

지정된 해결 메시지를 사용하여 ObsoleteAttribute 클래스의 새 인스턴스를 초기화합니다.

ObsoleteAttribute(String, Boolean)

해결 메시지와, 오래된 요소를 사용하는 것이 오류로 간주되는지 여부를 나타내는 부울 값을 사용하여 ObsoleteAttribute 클래스의 새 인스턴스를 초기화합니다.

속성

DiagnosticId

API 사용을 보고할 때 컴파일러가 사용할 ID를 가져오거나 설정합니다.

IsError

컴파일러에서 오래된 프로그램 요소를 사용하는 것을 오류로 처리할지 여부를 나타내는 값을 가져옵니다.

Message

해결 방법 메시지를 가져옵니다.

TypeId

파생 클래스에서 구현된 경우 이 Attribute에 대한 고유 식별자를 가져옵니다.

(다음에서 상속됨 Attribute)
UrlFormat

해당 설명서의 URL을 가져오거나 설정합니다. API가 실제 URL 대신 형식 문자열을 허용하여 진단 ID를 포함하는 일반 URL을 만듭니다.

메서드

Equals(Object)

이 인스턴스가 지정된 개체와 같은지를 나타내는 값을 반환합니다.

(다음에서 상속됨 Attribute)
GetHashCode()

이 인스턴스의 해시 코드를 반환합니다.

(다음에서 상속됨 Attribute)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
IsDefaultAttribute()

파생 클래스에서 재정의된 경우 이 인스턴스 값이 파생 클래스에 대한 기본값인지 여부를 표시합니다.

(다음에서 상속됨 Attribute)
Match(Object)

파생 클래스에서 재정의된 경우 이 인스턴스가 지정된 개체와 같은지 여부를 나타내는 값을 반환합니다.

(다음에서 상속됨 Attribute)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

이름 집합을 해당하는 디스패치 식별자 집합에 매핑합니다.

(다음에서 상속됨 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

인터페이스의 형식 정보를 가져오는 데 사용할 수 있는 개체의 형식 정보를 검색합니다.

(다음에서 상속됨 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

개체에서 제공하는 형식 정보 인터페이스의 수를 검색합니다(0 또는 1).

(다음에서 상속됨 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

개체에서 노출하는 메서드와 속성에 대한 액세스를 제공합니다.

(다음에서 상속됨 Attribute)

적용 대상

추가 정보