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 コードは削除されます。

注釈

アナライザーは、この属性を使用して、callite がプロパティの呼び出しによって保護されている場合に、その機能を必要とする注釈が付けられたコードの呼び出しに対する警告を防ぐことができます。

コンストラクター

名前 説明
FeatureGuardAttribute(Type)

FeatureGuardAttribute クラスの新しいインスタンスを初期化します。

指定した機能の種類を使用します。

プロパティ

名前 説明
FeatureType

プロパティによって保護される機能を表す型。

TypeId

派生クラスで実装されている場合は、この Attributeの一意の識別子を取得します。

(継承元 Attribute)

メソッド

名前 説明
Equals(Object)

このインスタンスが指定したオブジェクトと等しいかどうかを示す値を返します。

(継承元 Attribute)
GetHashCode()

このインスタンスのハッシュ コードを返します。

(継承元 Attribute)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
IsDefaultAttribute()

派生クラスでオーバーライドされた場合、このインスタンスの値が派生クラスの既定値であるかどうかを示します。

(継承元 Attribute)
Match(Object)

派生クラスでオーバーライドされた場合、このインスタンスが指定したオブジェクトと等しいかどうかを示す値を返します。

(継承元 Attribute)
MemberwiseClone()

現在の Objectの簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

適用対象