편집

다음을 통해 공유


PreserveAttribute Class

Definition

Prevents the MonoTouch linker from linking the target.

[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Struct | System.AttributeTargets.Enum | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Field | System.AttributeTargets.Event | System.AttributeTargets.Interface | System.AttributeTargets.Delegate, AllowMultiple=true)]
public sealed class PreserveAttribute : Attribute
type PreserveAttribute = class
    inherit Attribute
Inheritance
PreserveAttribute
Attributes

Remarks

This attribute is used at link time by the MonoTouch linker to skip certain classes, structures, enumerations or other objects from being linked.

By applying this attribute all of the members of the target will be kept as if they had been referenced by the code.

This attribute is useful for example when using classes that use reflection (for example web services) and that use this information for serialization and deserialization.

Starting with MonoTouch 6.0.9 this attribute can also be used at the assembly level, effectively duplicating the same behaviour as --linkskip=ASSEMBLY but without the need to duplicate the extra argument to every project.

You do not actually need to take a dependency on the Xamarin assemblies, for example, if you are a third-party developer that is creating a component or nuget package that is safe to be linked, you can just include the LinkerSafe attribute source code in your application, and the Xamarin linker will recognize it.

To use in an assembly, without taking a dependency in Xamarin's assemblies:

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

[assembly:Preserve]

Constructors

PreserveAttribute()

Instruct the MonoTouch linker to preserve the decorated code

PreserveAttribute(Type)

Fields

AllMembers

Ensures that all members of this type are preserved.

Conditional

Flags the method as a method to preserve during linking if the container class is pulled in.

Applies to