編輯

共用方式為


BindAsAttribute Class

Definition

The BindAsAttribute allows binding native NSNumber, NSValue and NSString (for enums) types into more accurate managed types.

[System.AttributeUsage(System.AttributeTargets.Property | System.AttributeTargets.Parameter | System.AttributeTargets.ReturnValue, AllowMultiple=false)]
public class BindAsAttribute : Attribute
type BindAsAttribute = class
    inherit Attribute
Inheritance
BindAsAttribute
Attributes

Remarks

This attribute is typically used in binding projects, to indicate a special mapping between Objective-C and managed types:

// NSValue <-> CGRect (for the 'rect' parameter)
// NSNumber <-> bool? (for the return value)
[return: BindAs (typeof (bool?))]
[Export ("shouldDrawAt:")]
NSNumber ShouldDraw ([BindAs (typeof (CGRect))] NSValue rect);

// NSString <-> CAScroll
[BindAs (typeof (CAScroll []))]
[Export ("supportedScrollModes")]
NSString [] SupportedScrollModes { get; set; }

In this example, the parameter will be bound as a managed CGRect, and the return value will be bound as bool?.

Supported combinations:
Between NSNumber and bool, byte, sbyte, short, ushort, int, uint, long, ulong, nint, nuint, float, double, nfloat, any of the previous as a nullable type, or as an array
Between NSValue and NSRange, CGAffineTransform, CGPoint, CGRect, CGSize, CGVector, NSDirectionalEdgeInsets, CATransform3d, CLLocationCoordinate2d, CMTime, CMTimeMapping, CMTimeRange, MKCoordinateSpan, SCNMatrix4, SCNVector3, SCNVector4, UIEdgeInsets, UIOffset, any of the previous as a nullable type, or as an array.
Between NSString-backed enums and the corresponding managed enum.

Constructors

BindAsAttribute(Type)

Initializes a new BindAs attribute with the specified managed type.

Fields

OriginalType

The Objective-C type.

Type

The managed type.

Applies to