ObsoleteAttribute Sınıf
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Artık kullanımda olmayan program öğelerini işaretler.
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
- Devralma
- Öznitelikler
Örnekler
Aşağıdaki örnek, özelliği ve özniteliğiyle ObsoleteAttribute işaretlenmiş bir yöntemi içeren bir sınıfı tanımlar. Koddaki özelliğin OldProperty değerine erişmek bir derleyici uyarısı oluşturur, ancak yöntemini çağırmak CallOldMethod bir derleyici hatası oluşturur. Örnek ayrıca kaynak kodu derlemeye çalıştığınızda elde ettiğiniz çıkışı da gösterir.
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())
' ~~~~~~~~~~~~~
Açıklamalar
Hiçbir değişiklik yapılmadan ObsoleteAttribute.cs'den içeri aktarılan kaynak kodu, sonuçta oluşan tüm uyarılar buna göre yoksayılır.
Oluşturucular
| Name | Description |
|---|---|
| ObsoleteAttribute() |
Sınıfın ObsoleteAttribute yeni bir örneğini varsayılan özelliklerle başlatır. |
| ObsoleteAttribute(String, Boolean) |
Sınıfın ObsoleteAttribute yeni bir örneğini geçici bir iletiyle ve eski öğe kullanımının hata olarak kabul edilip edilmediğini belirten boole değeriyle başlatır. |
| ObsoleteAttribute(String) |
Belirtilen geçici çözüm iletisiyle sınıfının yeni bir örneğini ObsoleteAttribute başlatır. |
Özellikler
| Name | Description |
|---|---|
| DiagnosticId |
API'nin kullanımını bildirirken derleyicinin kullanacağı kimliği alır veya ayarlar. |
| IsError |
Derleyicinin eski program öğesinin kullanımını hata olarak değerlendirip değerlendirmeyeceğini belirten bir değer alır. |
| Message |
Geçici çözüm iletisini alır. |
| TypeId |
Türetilmiş bir sınıfta uygulandığında, bu Attributeiçin benzersiz bir tanımlayıcı alır. (Devralındığı yer: Attribute) |
| UrlFormat |
İlgili belgelerin URL'sini alır veya ayarlar. API, gerçek URL yerine bir biçim dizesi kabul eder ve tanılama kimliğini içeren genel bir URL oluşturur. |
Yöntemler
| Name | Description |
|---|---|
| Equals(Object) |
Bu örneğin belirtilen bir nesneye eşit olup olmadığını gösteren bir değer döndürür. (Devralındığı yer: Attribute) |
| GetHashCode() |
Bu örneğin karma kodunu döndürür. (Devralındığı yer: Attribute) |
| GetType() |
Geçerli örneğin Type alır. (Devralındığı yer: Object) |
| IsDefaultAttribute() |
Türetilmiş bir sınıfta geçersiz kılındığında, bu örneğin değerinin türetilmiş sınıf için varsayılan değer olup olmadığını gösterir. (Devralındığı yer: Attribute) |
| Match(Object) |
Türetilmiş bir sınıfta geçersiz kılındığında, bu örneğin belirtilen bir nesneye eşit olup olmadığını gösteren bir değer döndürür. (Devralındığı yer: Attribute) |
| MemberwiseClone() |
Geçerli Objectbasit bir kopyasını oluşturur. (Devralındığı yer: Object) |
| ToString() |
Geçerli nesneyi temsil eden bir dize döndürür. (Devralındığı yer: Object) |
Belirtik Arabirim Kullanımları
| Name | Description |
|---|---|
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
Bir ad kümesini karşılık gelen bir dağıtma tanımlayıcısı kümesine eşler. (Devralındığı yer: Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
Bir arabirimin tür bilgilerini almak için kullanılabilecek bir nesnenin tür bilgilerini alır. (Devralındığı yer: Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
Bir nesnenin sağladığı tür bilgisi arabirimlerinin sayısını alır (0 ya da 1). (Devralındığı yer: Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
Bir nesne tarafından kullanıma sunulan özelliklere ve yöntemlere erişim sağlar. (Devralındığı yer: Attribute) |