語言

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 連結器用來跳過某些類別、結構、列舉或其他物件,避免被連結。

套用此屬性後,目標的所有成員將被保留為程式碼所參考的狀態。

此屬性在使用反射(例如網路服務)並利用這些資訊進行序列化與反序列化的類別中非常有用。

從 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]

建構函式

名稱 Description
PreserveAttribute()

指示 MonoTouch 連結器保留裝飾過的程式碼

PreserveAttribute(Type)

初始化一個以指定型別的新 PreserveAttribute 類別實例。

欄位

名稱 Description
AllMembers

確保所有此類成員均被保存。

Conditional

若容器類別被拉入,將該方法標記為連結時保留的方法。

適用於