FeatureGuardAttribute 類別

定義

表示指定的公用靜態布爾值只讀屬性可保護對指定功能的存取。

public ref class FeatureGuardAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Property, AllowMultiple=true, Inherited=false)]
public sealed class FeatureGuardAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Property, AllowMultiple=true, Inherited=false)>]
type FeatureGuardAttribute = class
    inherit Attribute
Public NotInheritable Class FeatureGuardAttribute
Inherits Attribute
繼承
FeatureGuardAttribute
屬性

範例

if (Feature.IsSupported)
    Feature.Implementation();

public class Feature
{
    [FeatureGuard(typeof(RequiresDynamicCodeAttribute))]
    internal static bool IsSupported => RuntimeFeature.IsDynamicCodeSupported;

    [RequiresDynamicCode("Feature requires dynamic code support.")]
    internal static Implementation() => ...; // Uses dynamic code
}

當應用程式以 建置 <PublishAot>true</PublishAot>時,呼叫 Feature.Implementation() 不會產生分析器警告 IL3050 ,且 Feature.Implementation 發佈時程式碼會被移除。

備註

分析器可以利用此屬性防止在呼叫該屬性時,對標註為需要該功能的呼叫程式碼發出警告。

建構函式

名稱 Description
FeatureGuardAttribute(Type)

初始化一個新FeatureGuardAttribute類別的實例

並以指定的特徵類型。

屬性

名稱 Description
FeatureType

代表該屬性所守護特徵的類型。

TypeId

在衍生類別中實作時,取得這個 Attribute的唯一標識碼。

(繼承來源 Attribute)

方法

名稱 Description
Equals(Object)

傳回值,這個值表示這個實例是否等於指定的物件。

(繼承來源 Attribute)
GetHashCode()

傳回這個實例的哈希碼。

(繼承來源 Attribute)
GetType()

取得目前實例的 Type

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,指出這個實例的值是否為衍生類別的預設值。

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,傳回值,指出這個實例是否等於指定的物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)

適用於