-
Notifications
You must be signed in to change notification settings - Fork 519
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Bgen] Simplify the NSValue BindAS generated code. (#22257)
As with previous changes, move to use a method group instead of a lambda with a using block. We only add the new methods in those platforms that have the specifict frameworks by using partial class. That way we keep the code cleaner than with a collection of #if statements. --------- Co-authored-by: GitHub Actions Autoformatter <[email protected]>
- Loading branch information
1 parent
486ffef
commit 74636f5
Showing
11 changed files
with
404 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
using ObjCRuntime; | ||
using CoreAnimation; | ||
|
||
#nullable enable | ||
|
||
namespace Foundation; | ||
|
||
public partial class NSValue : NSObject { | ||
|
||
/// <summary> | ||
/// Converts a native handle to a CATransform3D. | ||
/// </summary> | ||
/// <param name="handle">The native handle.</param> | ||
/// <returns>The CATransform3D.</returns> | ||
public static CATransform3D ToCATransform3D (NativeHandle handle) | ||
{ | ||
using var nsvalue = Runtime.GetNSObject<NSValue> (handle)!; | ||
return nsvalue.CATransform3DValue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
using CoreGraphics; | ||
using ObjCRuntime; | ||
|
||
#nullable enable | ||
|
||
namespace Foundation; | ||
|
||
public partial class NSValue : NSObject { | ||
|
||
/// <summary> | ||
/// Converts a native handle to a CGAffineTransform. | ||
/// </summary> | ||
/// <param name="handle">The native handle.</param> | ||
/// <returns>The CGAffineTransform.</returns> | ||
public static CGAffineTransform ToCGAffineTransform (NativeHandle handle) | ||
{ | ||
using var nsvalue = Runtime.GetNSObject<NSValue> (handle)!; | ||
return nsvalue.CGAffineTransformValue; | ||
} | ||
|
||
/// <summary> | ||
/// Converts a native handle to a CGPoint. | ||
/// </summary> | ||
/// <param name="handle">The native handle.</param> | ||
/// <returns>The CGPoint.</returns> | ||
public static CGPoint ToCGPoint (NativeHandle handle) | ||
{ | ||
using var nsvalue = Runtime.GetNSObject<NSValue> (handle)!; | ||
return nsvalue.CGPointValue; | ||
} | ||
|
||
/// <summary> | ||
/// Converts a native handle to a CGRect. | ||
/// </summary> | ||
/// <param name="handle">The native handle.</param> | ||
/// <returns>The CGRect.</returns> | ||
public static CGRect ToCGRect (NativeHandle handle) | ||
{ | ||
using var nsvalue = Runtime.GetNSObject<NSValue> (handle)!; | ||
return nsvalue.CGRectValue; | ||
} | ||
|
||
/// <summary> | ||
/// Converts a native handle to a CGSize. | ||
/// </summary> | ||
/// <param name="handle">The native handle.</param> | ||
/// <returns>The CGSize.</returns> | ||
public static CGSize ToCGSize (NativeHandle handle) | ||
{ | ||
using var nsvalue = Runtime.GetNSObject<NSValue> (handle)!; | ||
return nsvalue.CGSizeValue; | ||
} | ||
|
||
#if MONOMAC | ||
|
||
// @encode(CGAffineTransform) -> "{CGAffineTransform=dddddd}" but... | ||
// using a C string crash on macOS (while it works fine on iOS) | ||
[DllImport ("__Internal")] | ||
extern static IntPtr xamarin_encode_CGAffineTransform (); | ||
|
||
// The `+valueWithCGAffineTransform:` selector comes from UIKit and is not available on macOS | ||
public unsafe static NSValue FromCGAffineTransform (CGAffineTransform tran) | ||
{ | ||
return Create ((IntPtr) (void*) &tran, xamarin_encode_CGAffineTransform ()); | ||
} | ||
|
||
// The `CGAffineTransformValue` selector comes from UIKit and is not available on macOS | ||
public unsafe virtual CGAffineTransform CGAffineTransformValue { | ||
get { | ||
var result = new CGAffineTransform (); | ||
// avoid potential buffer overflow since we use the older `getValue:` API to cover all platforms | ||
// and we can cheat here with the actual string comparison (since we are the one doing it) | ||
if (ObjCType == "{CGAffineTransform=dddddd}") | ||
StoreValueAtAddress ((IntPtr) (void*) &result); | ||
return result; | ||
} | ||
} | ||
|
||
#else | ||
|
||
/// <summary> | ||
/// Converts a native handle to a CGVector. | ||
/// </summary> | ||
/// <param name="handle">The native handle.</param> | ||
/// <returns>The CGVector.</returns> | ||
public static CGVector ToCGVector (NativeHandle handle) | ||
{ | ||
using var nsvalue = Runtime.GetNSObject<NSValue> (handle)!; | ||
return nsvalue.CGVectorValue; | ||
} | ||
|
||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
using ObjCRuntime; | ||
using CoreLocation; | ||
|
||
#nullable enable | ||
|
||
namespace Foundation; | ||
|
||
public partial class NSValue : NSObject { | ||
|
||
/// <summary> | ||
/// Converts a native handle to a CLLocationCoordinate2D. | ||
/// </summary> | ||
/// <param name="handle">The native handle.</param> | ||
/// <returns>The CLLocationCoordinate2D.</returns> | ||
public static CLLocationCoordinate2D ToCLLocationCoordinate2D (NativeHandle handle) | ||
{ | ||
using var nsvalue = Runtime.GetNSObject<NSValue> (handle)!; | ||
return nsvalue.CoordinateValue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
using ObjCRuntime; | ||
using CoreMedia; | ||
|
||
#nullable enable | ||
|
||
namespace Foundation; | ||
|
||
public partial class NSValue : NSObject { | ||
|
||
/// <summary> | ||
/// Converts a native handle to a CMTime. | ||
/// </summary> | ||
/// <param name="handle">The native handle.</param> | ||
/// <returns>The CMTime.</returns> | ||
public static CMTimeRange ToCMTimeRange (NativeHandle handle) | ||
{ | ||
using var nsvalue = Runtime.GetNSObject<NSValue> (handle)!; | ||
return nsvalue.CMTimeRangeValue; | ||
} | ||
|
||
/// <summary> | ||
/// Converts a native handle to a CMTime. | ||
/// </summary> | ||
/// <param name="handle">The native handle.</param> | ||
/// <returns>The CMTime.</returns> | ||
public static CMTime ToCMTime (NativeHandle handle) | ||
{ | ||
using var nsvalue = Runtime.GetNSObject<NSValue> (handle)!; | ||
return nsvalue.CMTimeValue; | ||
} | ||
|
||
/// <summary> | ||
/// Converts a native handle to a CMTimeMapping. | ||
/// </summary> | ||
/// <param name="handle">The native handle.</param> | ||
/// <returns>The CMTimeMapping.</returns> | ||
public static CMTimeMapping ToCMTimeMapping (NativeHandle handle) | ||
{ | ||
using var nsvalue = Runtime.GetNSObject<NSValue> (handle)!; | ||
return nsvalue.CMTimeMappingValue; | ||
} | ||
|
||
/// <summary> | ||
/// Converts a native handle to a CMTimeRange. | ||
/// </summary> | ||
/// <param name="handle">The native handle.</param> | ||
/// <returns>The CMTimeRange.</returns> | ||
public static CMVideoDimensions ToCMVideoDimensions (NativeHandle handle) | ||
{ | ||
using var nsvalue = Runtime.GetNSObject<NSValue> (handle)!; | ||
return nsvalue.CMVideoDimensionsValue; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
using ObjCRuntime; | ||
using MapKit; | ||
|
||
#nullable enable | ||
|
||
namespace Foundation; | ||
|
||
public partial class NSValue : NSObject { | ||
|
||
/// <summary> | ||
/// Converts a native handle to a MKCoordinateRegion. | ||
/// </summary> | ||
/// <param name="handle">The native handle.</param> | ||
/// <returns>The MKCoordinateRegion.</returns> | ||
public static MKCoordinateSpan ToMKCoordinateSpan (NativeHandle handle) | ||
{ | ||
using var nsvalue = Runtime.GetNSObject<NSValue> (handle)!; | ||
return nsvalue.CoordinateSpanValue; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
using ObjCRuntime; | ||
using SceneKit; | ||
|
||
#nullable enable | ||
|
||
namespace Foundation; | ||
|
||
public partial class NSValue : NSObject { | ||
|
||
/// <summary> | ||
/// Converts a native handle to a SCNMatrix4. | ||
/// </summary> | ||
/// <param name="handle">The native handle.</param> | ||
/// <returns>The SCNMatrix4.</returns> | ||
public static SCNMatrix4 ToSCNMatrix4 (NativeHandle handle) | ||
{ | ||
using var nsvalue = Runtime.GetNSObject<NSValue> (handle)!; | ||
return nsvalue.SCNMatrix4Value; | ||
} | ||
|
||
/// <summary> | ||
/// Converts a native handle to a NSRange. | ||
/// </summary> | ||
/// <param name="handle">The native handle.</param> | ||
/// <returns>The NSRange.</returns> | ||
public static NSRange ToNSRange (NativeHandle handle) | ||
{ | ||
using var nsvalue = Runtime.GetNSObject<NSValue> (handle)!; | ||
return nsvalue.RangeValue; | ||
} | ||
|
||
/// <summary> | ||
/// Converts a native handle to a SCNVector3. | ||
/// </summary> | ||
/// <param name="handle">The native handle.</param> | ||
/// <returns>The SCNVector3.</returns> | ||
public static SCNVector3 ToSCNVector3 (NativeHandle handle) | ||
{ | ||
using var nsvalue = Runtime.GetNSObject<NSValue> (handle)!; | ||
return nsvalue.Vector3Value; | ||
} | ||
|
||
/// <summary> | ||
/// Converts a native handle to a SCNVector4. | ||
/// </summary> | ||
/// <param name="handle">The native handle.</param> | ||
/// <returns>The SCNVector4.</returns> | ||
public static SCNVector4 ToSCNVector4 (NativeHandle handle) | ||
{ | ||
using var nsvalue = Runtime.GetNSObject<NSValue> (handle)!; | ||
return nsvalue.Vector4Value; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
using ObjCRuntime; | ||
using UIKit; | ||
|
||
#nullable enable | ||
|
||
namespace Foundation; | ||
|
||
public partial class NSValue : NSObject { | ||
|
||
/// <summary> | ||
/// Converts a native handle to a UIEdgeInsets. | ||
/// </summary> | ||
/// <param name="handle">The native handle.</param> | ||
/// <returns>The UIEdgeInsets.</returns> | ||
public static UIEdgeInsets ToUIEdgeInsets (NativeHandle handle) | ||
{ | ||
using var nsvalue = Runtime.GetNSObject<NSValue> (handle)!; | ||
return nsvalue.UIEdgeInsetsValue; | ||
} | ||
|
||
/// <summary> | ||
/// Converts a native handle to a UIOffset. | ||
/// </summary> | ||
/// <param name="handle">The native handle.</param> | ||
/// <returns>The UIOffset.</returns> | ||
public static UIOffset ToUIOffset (NativeHandle handle) | ||
{ | ||
using var nsvalue = Runtime.GetNSObject<NSValue> (handle)!; | ||
return nsvalue.UIOffsetValue; | ||
} | ||
|
||
/// <summary> | ||
/// Converts a native handle to a NSDirectionalEdgeInsets. | ||
/// </summary> | ||
/// <param name="handle">The native handle.</param> | ||
/// <returns>The NSDirectionalEdgeInsets.</returns> | ||
public static NSDirectionalEdgeInsets ToNSDirectionalEdgeInsets (NativeHandle handle) | ||
{ | ||
using var nsvalue = Runtime.GetNSObject<NSValue> (handle)!; | ||
return nsvalue.DirectionalEdgeInsetsValue; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.
This comment was marked as outdated.
Sorry, something went wrong.