PreserveAttribute 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
阻止 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 。
例如,如果你是第三方开发人员正在创建可安全链接的组件或 nuget 包,则实际上不需要依赖Xamarin程序集,并且Xamarin链接器将识别它。
若要在程序集中使用,无需在Xamarin的程序集中使用依赖项:
[System.AttributeUsage(System.AttributeTargets.All)]
class PreserveAttribute : System.Attribute {
public PreserveAttribute () {}
public bool Conditional { get; set; }
}
[assembly:Preserve]
构造函数
| 名称 | 说明 |
|---|---|
| PreserveAttribute() |
指示 MonoTouch 链接器保留修饰的代码 |
| PreserveAttribute(Type) |
使用指定类型初始化类的新实例 PreserveAttribute 。 |
字段
| 名称 | 说明 |
|---|---|
| AllMembers |
确保保留此类型的所有成员。 |
| Conditional |
将方法标记为在链接过程中保留的方法(如果拉入容器类)。 |