xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.46k stars 511 forks source link

NSValueTransformerNameBindingOption binding is missing #17983

Open snechaev opened 1 year ago

snechaev commented 1 year ago

Task description

I need to call NSObject.Bind from code and specify value transformer for this binding. I bind my custom view, so I can't configure the binding via the XCode UI (as IB_DESIGNABLE and IBInspectable is not supported)

So, reference swift code for this task is a following

myObj.bind(key,
        toObject: objToBind
        withKeyPath: keyPath
        options: [NSValueTransformerNameBindingOption:
                                 NSNegateBooleanTransformerName])

My current version of C# code:

var AppKit_libHandle = Dlfcn.dlopen(Constants.AppKitLibrary, 0);
var bindingOptionKey = Dlfcn.GetStringConstant(AppKit_libHandle,
                                          "NSValueTransformerNameBindingOption");
var options = NSDictionary.FromObjectAndKey(Foundation.NSValueTransformer.BooleanTransformerName,
                                                                                 bindingOptionKey);
Dlfcn.dlclose(AppKit_libHandle);

myObj.Bind(key, objToBind, keyPath, options);

This works as expected, but a dlopen-related stuff looks a little bit wired and not maintainable.

Am I missing something or it is really no ready-to-use binded value for NSValueTransformerNameBindingOption?

Apple documentation: https://developer.apple.com/documentation/appkit/nsvaluetransformernamebindingoption?language=objc

Expected Behavior

There is a ready-to-use constant for NSValueTransformerNameBindingOption, no dlopen-stuff needed to perform a task.

Actual Behavior

NSValueTransformerNameBindingOption is not binded, so dlopen-stuff is needed to perform a task.

Environment

Version information ``` Visual Studio Professional 2022 for Mac Version 17.5.3 (build 15) Installation UUID: 9dc06737-29f0-43a7-b4a8-9aab46a6f912 Runtime .NET 7.0.1 (64-bit) Architecture: X64 Microsoft.macOS.Sdk 12.3.2372; git-rev-head:754abbf6a3563f6267e5717ae832b4ac25b1f2fb; git-branch:release/7.0.1xx-xcode13.3 Roslyn (Language Service) 4.5.0-3.23056.2+97881342e427ff5cdcba8f12b12ff8e6f3564431 NuGet Version: 6.4.0.117 .NET SDK (x64) SDK: /usr/local/share/dotnet/sdk/7.0.202/Sdks SDK Versions: 7.0.202 7.0.201 6.0.407 6.0.406 MSBuild SDKs: /Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/Sdks .NET Runtime (x64) Runtime: /usr/local/share/dotnet/dotnet Runtime Versions: 7.0.4 7.0.3 6.0.15 6.0.14 Xamarin.Profiler Version: 1.8.0.49 Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler Updater Version: 11 Xamarin.Android Not Installed Microsoft Build of OpenJDK Java SDK: /Library/Java/JavaVirtualMachines/microsoft-11.jdk 11.0.16.1 Android Designer EPL code available here: https://github.com/xamarin/AndroidDesigner.EPL Eclipse Temurin JDK Java SDK: /Library/Java/JavaVirtualMachines/temurin-8.jdk 1.8.0.302 Android Designer EPL code available here: https://github.com/xamarin/AndroidDesigner.EPL Android SDK Manager Version: 17.5.0.33 Hash: f0c0c52 Branch: remotes/origin/d17-5~2 Build date: 2023-03-23 16:21:22 UTC Android Device Manager Version: 0.0.0.1245 Hash: 7f8a990 Branch: 7f8a990 Build date: 2023-03-23 16:21:23 UTC Xamarin Designer Version: 17.5.3.47 Hash: e8b5d371c3 Branch: remotes/origin/d17-5 Build date: 2023-03-23 16:21:17 UTC Apple Developer Tools Xcode: 14.2 21534 Build: 14C18 Xamarin.Mac Version: 9.1.0.5 Visual Studio Professional Hash: 7738c90c9 Branch: xcode14.2 Build date: 2023-01-25 15:56:14-0500 Xamarin.iOS Version: 16.2.0.5 Visual Studio Professional Hash: 7738c90c9 Branch: xcode14.2 Build date: 2023-01-25 15:56:15-0500 Build Information Release ID: 1705030015 Git revision: c7ec3826dd11045a53fa7f2c08ddbd6bd475c05b Build date: 2023-03-23 16:19:44+00 Build branch: release-17.5 Build lane: release-17.5 Operating System Mac OS X 13.2.1 Darwin 22.3.0 Darwin Kernel Version 22.3.0 Mon Jan 30 20:42:11 PST 2023 root:xnu-8792.81.3~2/RELEASE_X86_64 x86_64 Enabled user installed extensions Log Monitor 0.8 ```

P.S. As a side note: there are a lot other binding options keys exists (apple docs) and looks like none of them are binded in Xamarin..

dalexsoto commented 1 year ago

Hello, there is no particular reason on why it wasn't bound, probably it was just an oversight of the initial AppKit binding. I have marked this as good first issue and all help is truly appreciated!