Skip to content

Commit

Permalink
[Foundation] Unify a few NSAttributedString functions. (#16782)
Browse files Browse the repository at this point in the history
Unify the code for the following functions:

* NSAttributedString.GetData[FromRange]
* NSAttributedString.GetFileWrapper[FromRange]

These functions use 'ref' arguments instead of 'out' arguments for mobile
platforms (likely due to the generator not having proper 'out' parameter
support when these functions were implemented), so improve to use 'out'
parameters in XAMCORE_5_0 (and macOS, where they already use 'out'
parameters).

Also fix nullability.

Ref: #15216
  • Loading branch information
rolfbjarne authored Nov 17, 2022
1 parent bedcbb0 commit 95783db
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 48 deletions.
74 changes: 44 additions & 30 deletions src/foundation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,26 +347,6 @@ partial interface NSAttributedString : NSCoding, NSMutableCopying, NSSecureCodin
[iOS (7,0)]
[Wrap ("this (data, options.GetDictionary ()!, out resultDocumentAttributes, ref error)")]
NativeHandle Constructor (NSData data, NSAttributedStringDocumentAttributes options, out NSDictionary resultDocumentAttributes, ref NSError error);

[NoMac]
[iOS (7,0)]
[Export ("dataFromRange:documentAttributes:error:")]
NSData GetDataFromRange (NSRange range, NSDictionary attributes, ref NSError error);

[NoMac]
[iOS (7,0)]
[Wrap ("GetDataFromRange (range, documentAttributes.GetDictionary ()!, ref error)")]
NSData GetDataFromRange (NSRange range, NSAttributedStringDocumentAttributes documentAttributes, ref NSError error);

[NoMac]
[iOS (7,0)]
[Export ("fileWrapperFromRange:documentAttributes:error:")]
NSFileWrapper GetFileWrapperFromRange (NSRange range, NSDictionary attributes, ref NSError error);

[NoMac]
[iOS (7,0)]
[Wrap ("GetFileWrapperFromRange (range, documentAttributes.GetDictionary ()!, ref error)")]
NSFileWrapper GetFileWrapperFromRange (NSRange range, NSAttributedStringDocumentAttributes documentAttributes, ref NSError error);
#endif

[Export ("initWithString:attributes:")]
Expand Down Expand Up @@ -496,23 +476,58 @@ partial interface NSAttributedString : NSCoding, NSMutableCopying, NSSecureCodin
[NoiOS][NoMacCatalyst][NoWatch][NoTV]
[Export ("itemNumberInTextList:atIndex:")]
nint GetItemNumber (NSTextList textList, nuint index);
#endif

[NoiOS][NoMacCatalyst][NoWatch][NoTV]
#if !(MONOMAC || XAMCORE_5_0)
[Sealed]
#endif
[return: NullAllowed]
[Export ("dataFromRange:documentAttributes:error:")]
NSData GetData (NSRange range, [NullAllowed] NSDictionary options, out NSError error);
NSData GetData (NSRange range, NSDictionary options, out NSError error);

[NoiOS][NoMacCatalyst][NoWatch][NoTV]
[Wrap ("this.GetData (range, options.GetDictionary (), out error)")]
[return: NullAllowed]
[Wrap ("this.GetData (range, options.GetDictionary ()!, out error)")]
NSData GetData (NSRange range, NSAttributedStringDocumentAttributes options, out NSError error);

[NoiOS][NoMacCatalyst][NoWatch][NoTV]
#if !(MONOMAC || XAMCORE_5_0)
[return: NullAllowed]
[Obsolete ("Use 'GetData' instead.")]
[Export ("dataFromRange:documentAttributes:error:")]
NSData GetDataFromRange (NSRange range, NSDictionary attributes, ref NSError error);
#endif

#if !(MONOMAC || XAMCORE_5_0)
[return: NullAllowed]
[Obsolete ("Use 'GetData' instead.")]
[Wrap ("GetDataFromRange (range, documentAttributes.GetDictionary ()!, ref error)")]
NSData GetDataFromRange (NSRange range, NSAttributedStringDocumentAttributes documentAttributes, ref NSError error);
#endif

#if !(MONOMAC || XAMCORE_5_0)
[Sealed]
#endif
[return: NullAllowed]
[Export ("fileWrapperFromRange:documentAttributes:error:")]
NSFileWrapper GetFileWrapper (NSRange range, [NullAllowed] NSDictionary options, out NSError error);
NSFileWrapper GetFileWrapper (NSRange range, NSDictionary options, out NSError error);

[NoiOS][NoMacCatalyst][NoWatch][NoTV]
[Wrap ("this.GetFileWrapper (range, options.GetDictionary (), out error)")]
#if !(MONOMAC || XAMCORE_5_0)
[return: NullAllowed]
[Obsolete ("Use 'GetFileWrapper' instead.")]
[Export ("fileWrapperFromRange:documentAttributes:error:")]
NSFileWrapper GetFileWrapperFromRange (NSRange range, NSDictionary attributes, ref NSError error);
#endif

[return: NullAllowed]
[Wrap ("this.GetFileWrapper (range, options.GetDictionary ()!, out error)")]
NSFileWrapper GetFileWrapper (NSRange range, NSAttributedStringDocumentAttributes options, out NSError error);

#if !(MONOMAC || XAMCORE_5_0)
[return: NullAllowed]
[Obsolete ("Use 'GetFileWrapper' instead.")]
[Wrap ("GetFileWrapperFromRange (range, documentAttributes.GetDictionary ()!, ref error)")]
NSFileWrapper GetFileWrapperFromRange (NSRange range, NSAttributedStringDocumentAttributes documentAttributes, ref NSError error);
#endif

[NoiOS][NoMacCatalyst][NoWatch][NoTV]
[Export ("RTFFromRange:documentAttributes:")]
NSData GetRtf (NSRange range, [NullAllowed] NSDictionary options);
Expand Down Expand Up @@ -544,15 +559,14 @@ partial interface NSAttributedString : NSCoding, NSMutableCopying, NSSecureCodin
[NoiOS][NoMacCatalyst][NoWatch][NoTV]
[Wrap ("this.GetDocFormat (range, options.GetDictionary ())")]
NSData GetDocFormat (NSRange range, NSAttributedStringDocumentAttributes options);
#else

[NoMac]
[Export ("drawWithRect:options:context:")]
void DrawString (CGRect rect, NSStringDrawingOptions options, [NullAllowed] NSStringDrawingContext context);

[NoMac]
[Export ("boundingRectWithSize:options:context:")]
CGRect GetBoundingRect (CGSize size, NSStringDrawingOptions options, [NullAllowed] NSStringDrawingContext context);
#endif

[MacCatalyst (13, 1)][TV (9, 0)][Mac (10, 0)][iOS (6, 0)]
[Export ("size")]
Expand Down
2 changes: 0 additions & 2 deletions tests/xtro-sharpie/api-annotations-dotnet/iOS-UIKit.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
!missing-null-allowed! 'Foundation.NSAttributedString UIKit.UIButton::get_CurrentAttributedTitle()' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSAttributedString UIKit.UIButton::GetAttributedTitle(UIKit.UIControlState)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSAttributedString UIKit.UIPickerViewDelegate::GetAttributedTitle(UIKit.UIPickerView,System.IntPtr,System.IntPtr)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSData Foundation.NSAttributedString::GetDataFromRange(Foundation.NSRange,Foundation.NSDictionary,Foundation.NSError&)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSData UIKit.UIPasteboard::DataForPasteboardType(System.String)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSData[] UIKit.UIPasteboard::GetDataForPasteboardType(System.String,Foundation.NSIndexSet)' is missing an [NullAllowed] on parameter #1
!missing-null-allowed! 'Foundation.NSData[] UIKit.UIPasteboard::GetDataForPasteboardType(System.String,Foundation.NSIndexSet)' is missing an [NullAllowed] on return type
Expand All @@ -108,7 +107,6 @@
!missing-null-allowed! 'Foundation.NSDictionary UIKit.UIMotionEffect::ComputeKeyPathsAndRelativeValues(UIKit.UIOffset)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSDictionary UIKit.UISearchBar::_GetScopeBarButtonTitleTextAttributes(UIKit.UIControlState)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSDictionary UIKit.UISegmentedControl::_GetTitleTextAttributes(UIKit.UIControlState)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSFileWrapper Foundation.NSAttributedString::GetFileWrapperFromRange(Foundation.NSRange,Foundation.NSDictionary,Foundation.NSError&)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSIndexPath UIKit.UICollectionViewFocusUpdateContext::get_NextFocusedIndexPath()' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSIndexPath UIKit.UICollectionViewFocusUpdateContext::get_PreviouslyFocusedIndexPath()' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSIndexPath UIKit.UITableViewDelegate::WillDeselectRow(UIKit.UITableView,Foundation.NSIndexPath)' is missing an [NullAllowed] on return type
Expand Down
4 changes: 0 additions & 4 deletions tests/xtro-sharpie/api-annotations-dotnet/macOS-AppKit.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,6 @@
!missing-null-allowed! 'Foundation.NSData AppKit.NSPasteboardItem::GetDataForType(System.String)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSData AppKit.NSText::RtfdFromRange(Foundation.NSRange)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSData AppKit.NSText::RtfFromRange(Foundation.NSRange)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSData Foundation.NSAttributedString::GetData(Foundation.NSRange,Foundation.NSDictionary,Foundation.NSError&)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSData Foundation.NSAttributedString::GetDocFormat(Foundation.NSRange,Foundation.NSDictionary)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSData Foundation.NSAttributedString::GetRtf(Foundation.NSRange,Foundation.NSDictionary)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSData Foundation.NSAttributedString::GetRtfd(Foundation.NSRange,Foundation.NSDictionary)' is missing an [NullAllowed] on return type
Expand All @@ -531,7 +530,6 @@
!missing-null-allowed! 'Foundation.NSExpression[] AppKit.NSPredicateEditorRowTemplate::get_LeftExpressions()' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSExpression[] AppKit.NSPredicateEditorRowTemplate::get_RightExpressions()' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSFileWrapper AppKit.NSDocument::GetAsFileWrapper(System.String,Foundation.NSError&)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSFileWrapper Foundation.NSAttributedString::GetFileWrapper(Foundation.NSRange,Foundation.NSDictionary,Foundation.NSError&)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSFileWrapper Foundation.NSAttributedString::GetRtfdFileWrapper(Foundation.NSRange,Foundation.NSDictionary)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSIndexPath AppKit.NSTreeController::GetSelectionIndexPath()' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSIndexSet AppKit.NSBrowser::SelectedRowIndexes(System.IntPtr)' is missing an [NullAllowed] on return type
Expand Down Expand Up @@ -1121,11 +1119,9 @@
!extra-null-allowed! 'AppKit.NSMenu AppKit.NSTextCheckingController::GetMenu(System.UIntPtr,System.Boolean,Foundation.NSRange&)' has a extraneous [NullAllowed] on parameter #2
!extra-null-allowed! 'Foundation.NSArray AppKit.NSTokenFieldCellDelegate::GetCompletionStrings(AppKit.NSTokenFieldCell,System.String,System.IntPtr,System.IntPtr&)' has a extraneous [NullAllowed] on parameter #3
!extra-null-allowed! 'Foundation.NSData AppKit.NSBitmapImageRep::RepresentationUsingTypeProperties(AppKit.NSBitmapImageFileType,Foundation.NSDictionary)' has a extraneous [NullAllowed] on parameter #1
!extra-null-allowed! 'Foundation.NSData Foundation.NSAttributedString::GetData(Foundation.NSRange,Foundation.NSDictionary,Foundation.NSError&)' has a extraneous [NullAllowed] on parameter #1
!extra-null-allowed! 'Foundation.NSData Foundation.NSAttributedString::GetDocFormat(Foundation.NSRange,Foundation.NSDictionary)' has a extraneous [NullAllowed] on parameter #1
!extra-null-allowed! 'Foundation.NSData Foundation.NSAttributedString::GetRtf(Foundation.NSRange,Foundation.NSDictionary)' has a extraneous [NullAllowed] on parameter #1
!extra-null-allowed! 'Foundation.NSData Foundation.NSAttributedString::GetRtfd(Foundation.NSRange,Foundation.NSDictionary)' has a extraneous [NullAllowed] on parameter #1
!extra-null-allowed! 'Foundation.NSFileWrapper Foundation.NSAttributedString::GetFileWrapper(Foundation.NSRange,Foundation.NSDictionary,Foundation.NSError&)' has a extraneous [NullAllowed] on parameter #1
!extra-null-allowed! 'Foundation.NSFileWrapper Foundation.NSAttributedString::GetRtfdFileWrapper(Foundation.NSRange,Foundation.NSDictionary)' has a extraneous [NullAllowed] on parameter #1
!extra-null-allowed! 'System.String[] AppKit.NSControlTextEditingDelegate::GetCompletions(AppKit.NSControl,AppKit.NSTextView,System.String[],Foundation.NSRange,System.IntPtr&)' has a extraneous [NullAllowed] on parameter #4
!extra-null-allowed! 'System.Void AppKit.NSCell::EditWithFrame(CoreGraphics.CGRect,AppKit.NSView,AppKit.NSText,Foundation.NSObject,AppKit.NSEvent)' has a extraneous [NullAllowed] on parameter #1
Expand Down
2 changes: 0 additions & 2 deletions tests/xtro-sharpie/api-annotations-dotnet/tvOS-UIKit.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,12 @@
!missing-null-allowed! 'Foundation.NSArray Foundation.NSBundle::LoadNib(System.String,Foundation.NSObject,Foundation.NSDictionary)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSAttributedString UIKit.UIButton::get_CurrentAttributedTitle()' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSAttributedString UIKit.UIButton::GetAttributedTitle(UIKit.UIControlState)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSData Foundation.NSAttributedString::GetDataFromRange(Foundation.NSRange,Foundation.NSDictionary,Foundation.NSError&)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSDictionary UIKit.UIBarItem::_GetTitleTextAttributes(UIKit.UIControlState)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSDictionary UIKit.UICollectionViewLayoutInvalidationContext::get_InvalidatedDecorationIndexPaths()' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSDictionary UIKit.UICollectionViewLayoutInvalidationContext::get_InvalidatedSupplementaryIndexPaths()' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSDictionary UIKit.UIMotionEffect::ComputeKeyPathsAndRelativeValues(UIKit.UIOffset)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSDictionary UIKit.UISearchBar::_GetScopeBarButtonTitleTextAttributes(UIKit.UIControlState)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSDictionary UIKit.UISegmentedControl::_GetTitleTextAttributes(UIKit.UIControlState)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSFileWrapper Foundation.NSAttributedString::GetFileWrapperFromRange(Foundation.NSRange,Foundation.NSDictionary,Foundation.NSError&)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSIndexPath UIKit.UICollectionViewFocusUpdateContext::get_NextFocusedIndexPath()' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSIndexPath UIKit.UICollectionViewFocusUpdateContext::get_PreviouslyFocusedIndexPath()' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSIndexPath UIKit.UITableViewDelegate::WillDeselectRow(UIKit.UITableView,Foundation.NSIndexPath)' is missing an [NullAllowed] on return type
Expand Down
2 changes: 0 additions & 2 deletions tests/xtro-sharpie/iOS-UIKit.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@
!missing-null-allowed! 'Foundation.NSAttributedString UIKit.UIButton::get_CurrentAttributedTitle()' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSAttributedString UIKit.UIButton::GetAttributedTitle(UIKit.UIControlState)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSAttributedString UIKit.UIPickerViewDelegate::GetAttributedTitle(UIKit.UIPickerView,System.nint,System.nint)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSData Foundation.NSAttributedString::GetDataFromRange(Foundation.NSRange,Foundation.NSDictionary,Foundation.NSError&)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSData UIKit.UIPasteboard::DataForPasteboardType(System.String)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSData[] UIKit.UIPasteboard::GetDataForPasteboardType(System.String,Foundation.NSIndexSet)' is missing an [NullAllowed] on parameter #1
!missing-null-allowed! 'Foundation.NSData[] UIKit.UIPasteboard::GetDataForPasteboardType(System.String,Foundation.NSIndexSet)' is missing an [NullAllowed] on return type
Expand All @@ -132,7 +131,6 @@
!missing-null-allowed! 'Foundation.NSDictionary UIKit.UIMotionEffect::ComputeKeyPathsAndRelativeValues(UIKit.UIOffset)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSDictionary UIKit.UISearchBar::_GetScopeBarButtonTitleTextAttributes(UIKit.UIControlState)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSDictionary UIKit.UISegmentedControl::_GetTitleTextAttributes(UIKit.UIControlState)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSFileWrapper Foundation.NSAttributedString::GetFileWrapperFromRange(Foundation.NSRange,Foundation.NSDictionary,Foundation.NSError&)' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSIndexPath UIKit.UICollectionViewFocusUpdateContext::get_NextFocusedIndexPath()' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSIndexPath UIKit.UICollectionViewFocusUpdateContext::get_PreviouslyFocusedIndexPath()' is missing an [NullAllowed] on return type
!missing-null-allowed! 'Foundation.NSIndexPath UIKit.UITableViewDelegate::WillDeselectRow(UIKit.UITableView,Foundation.NSIndexPath)' is missing an [NullAllowed] on return type
Expand Down
Loading

4 comments on commit 95783db

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.