Bug 37530 - NSAttributedString attributesAtIndex:effectiveRange: not bound
Summary: NSAttributedString attributesAtIndex:effectiveRange: not bound
Status: RESOLVED ANSWERED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 9.4 (iOS 9.2)
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-01-08 20:52 UTC by Frank A. Krueger
Modified: 2016-01-11 18:19 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Comment 1 Sebastien Pouliot 2016-01-08 22:45:36 UTC
> public NSDictionary GetAttributes (nint location, out NSRange effectiveRange)

is the bound version of "attributesAtIndex:effectiveRange:" in NSAttributedString

However the way it was done you need to override

> public virtual IntPtr LowLevelGetAttributes (nint location, out NSRange effectiveRange)

as the former is not virtual.

Git history brings me back to the original monotouch commit (2010-04-19) but I believe that the binding generator was not, at the time, able to handle this case.
Comment 2 Frank A. Krueger 2016-01-08 23:34:23 UTC
The problem is that there is no way to test effectiveRange against null with that signature. The docs explicitly allow that case and the function does get called that way.

For now, I'm doing my own override:

    [<Export ("attributesAtIndex:effectiveRange:")>]
    member this.GetAttributes (location : nint, effectiveRange : nativeint) : nativeint =
        if effectiveRange <> 0n then
            let range = NSRange (nint 0, data.Length)
            System.Runtime.InteropServices.Marshal.StructureToPtr (range, effectiveRange, false)
        attrs.Dictionary.Handle
Comment 3 Frank A. Krueger 2016-01-10 16:06:47 UTC
So this won't be fixed?
Comment 4 Sebastien Pouliot 2016-01-11 18:19:28 UTC
Not in the short term. It's how .NET works (non-nullable struct), which is not always the best in a ref/out case. Fixing this would be an API breaking change (without workarounds).

Your workaround, using a different signature, is the best way to test for null (even if it makes using the NSRange instance harder later).