Language

PreserveAttribute クラス

定義

MonoTouch リンカーがターゲットをリンクできないようにします。

[System.AttributeUsage(System.AttributeTargets.Assembly | 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, AllowMultiple=true)]
public sealed class PreserveAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Assembly | 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, AllowMultiple=true)>]
type PreserveAttribute = class
    inherit Attribute
継承
PreserveAttribute
属性

注釈

この属性は、MonoTouch リンカーがリンク時に使用して、特定のクラス、構造体、列挙型、またはその他のオブジェクトがリンクされないようにします。

この属性を適用すると、ターゲットのすべてのメンバーがコードによって参照されたかのように保持されます。

この属性は、リフレクション (Web サービスなど) を使用し、シリアル化と逆シリアル化にこの情報を使用するクラスを使用する場合に便利です。

MonoTouch 6.0.9 以降では、この属性はアセンブリ レベルでも使用でき、 --linkskip=ASSEMBLY と同じ動作を効果的に複製しますが、すべてのプロジェクトに余分な引数を複製する必要はありません。

実際には、Xamarin アセンブリに依存する必要はありません。たとえば、リンクしても安全なコンポーネントまたは nuget パッケージを作成しているサードパーティの開発者は、LinkerSafe 属性のソース コードをアプリケーションに含めるだけで、Xamarin リンカーはそれを認識できます。

Xamarinのアセンブリに依存関係を持たずにアセンブリで使用するには:

[System.AttributeUsage(System.AttributeTargets.All)]
class PreserveAttribute : System.Attribute {
    public PreserveAttribute () {}
    public bool Conditional { get; set; }
}

[assembly:Preserve]

コンストラクター

Name 説明
PreserveAttribute()

装飾されたコードを保持するように MonoTouch リンカーに指示する

PreserveAttribute(Type)

指定した型を使用して、 PreserveAttribute クラスの新しいインスタンスを初期化します。

フィールド

Name 説明
AllMembers

この型のすべてのメンバーが保持されていることを確認します。

Conditional

コンテナー クラスがプルされた場合に、リンク中に保持するメソッドとしてメソッドにフラグを設定します。

適用対象